How can I fail a TeamCity build if dotCover doesn't report a high enough result?
Asked Answered
U

1

6

I would like TeamCity to run my mSpec tests and report on the code covered by the tests.

I would also like TeamCity to report that a build has failed if code coverage in certain namespaces doesn't meet a threshold (e.g. MyProduct.ImportantStuff must be 100%, but MyProduct.LegacyStuff must be [23% or whatever it currently is to ensure we don't add new stuff without covering tests].

I initially looked at dotCover as it's integrated into TeamCity. I have since been looking at OpenCover as I couldn't get TC to fail the build on low coverage.

I got OpenCover working but I would still like to know (as I'm sure a lot of people would) how to get TC to fail a build if code coverage is too low.

Unsophisticated answered 24/4, 2012 at 11:12 Comment(1)
Just to provide feedback on your problem with TC and dotCover not failing on low coverage. This URL confirms that the problem may be with the metric you chose to report on. What you should be using is percentage of statement coverage - teamcity-support.jetbrains.com/hc/en-us/community/posts/…World
T
6

Are you using the latest TeamCity, ie version 7?

When setting up a build configuration you can specify this:

enter image description here

There are lots more options in the dropdown related to code coverage. You can also force your build to fail if you're using some other code coverage tool. For example you can echo a line to the console that will then be picked up by teamcity :

##teamcity[buildStatus status='FAILURE' text='something failed']

see official docs on this here

Tornado answered 24/4, 2012 at 13:33 Comment(3)
Hi @Wal. Yes, using latest version. I was specifically looking for a way to fail if certain assemblies fell below a certain percentage. This doesn't seem achievable with the built-in stuff. I can achieve the desired results by using OpenCover, then running ReportGenerator, then performing a few XPath queries in the summary XML.Unsophisticated
ok, and then you can emit (to the Console) ##teamcity[buildStatus status='FAILURE' to send the message to TC. Follow that link in my post to see the full syntaxTornado
This is a great workaround for when TC ignores error codes and happily says "Process exited with code 0". Magical!Schematism

© 2022 - 2024 — McMap. All rights reserved.