I have a TeamCity build that captures code coverage for unit tests. I have also defined an environment variable for the minimum code coverage for the build to succeed, which works fine but I don't like to maintain this threshold manually. The question I have is whether there is a way (outside of publishing code coverage statistics somewhere outside of TeamCity and then reading the results from the last successful build) to automatically adjust the threshold as code coverage improves to ensure that it's a steady improvement without allowing backsliding :)?
For example, suppose the current code coverage is 20% (a legacy application) and as new unit tests are written, code coverage improves to 25%. Then, someone checks in new code without unit tests and code coverage drops to 24%. I would want TeamCity to fail the build because code coverage dropped from 25% to 24%.
To get the code coverage information displayed in TeamCity for the supported tools, you need to configure it in the dedicated section of a build runner's settings page. The following build runners include code coverage support: The code coverage results can be viewed on the Overview tab of Build Results.
299. This answer is not useful. Save this answer. Show activity on this post. Code coverage is a measurement of how many lines/blocks/arcs of your code are executed while the automated tests are running.
I have some pet theories about code coverage which I'd like to explain first before I get on to answering the question.
First some context:
I have a theory that you should divide your code into just two divisions as far as code coverage is concerned:
Either division could be constituted by a number of projects, but members of a division should be files (given that both Java and C# have source files) and preferably whole folders of files. You could have one set of project in the first division and another set in the second division.
Now the report of lack of coverage is just the number of lines in the second division.
The mode of operation should be that you are testing your code as you go and code simply falls into the 100% coverage division. However, if you find a tricky piece of code which your brain just can't find a way to test, you should refactor so that the bits that aren't tested move into the second division. Alternatively you may get a brainwave and be able to find a test which raises the second division above 0%, at which point you refactor the code over to the first division. This means that every check-in maintains my theoretical invariant.
Now, back to the question:
No, I don't know TeamCity at all apart from a brief look at the JetBrains website, so I don't know how to update the coverage, but according to my theory it should be 100% or nothing, so can you set limits per project? If you can, then a fixed limit of 100% works for the first division.
If you can get two divisions you may want to do the automatic update thing with a lines of code metric for the second division, progressively lower is better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With