如果dotCover报告的结果不够高,如何使TeamCity构建失败?

如果dotCover报告的结果不够高,如何使TeamCity构建失败?

问题描述:

我希望TeamCity运行我的mSpec测试并报告测试涵盖的代码.

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

我还希望TeamCity报告构建失败,如果某些命名空间中的代码覆盖率未达到阈值(例如,MyProduct.ImportantStuff必须为 100% ,但MyProduct.LegacyStuff必须为[ 23% 或目前使用的其他值,以确保我们不会覆盖测试而不会添加新内容].

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].

最初,我将dotCover集成到TeamCity中.此后,我一直在关注OpenCover,因为我无法让TC在低覆盖率的基础上失败.

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.

我让OpenCover工作,但我仍然想知道(我相信很多人会)在代码覆盖率太低的情况下如何使TC无法通过构建.

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.

您是否正在使用最新的TeamCity,即版本7?

Are you using the latest TeamCity, ie version 7?

设置构建配置时,您可以指定以下内容:

When setting up a build configuration you can specify this:

下拉菜单中还有很多个与代码覆盖率相关的选项.如果您使用其他代码覆盖工具,也可以强制构建失败. 例如,您可以在控制台上回显一行,然后由teamcity接听:

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']

在此此处