2

I'm trying to fail builds in Visual Studio Online when Code Coverage is below a threshold.

Is there anyway to do it under Visual Studio Online or I have to do it using the XAML Build Definitions.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
ELE
  • 23
  • 1
  • 4
  • 3
    I'd argue that you shouldn't do that. Code coverage gives you useful information on areas of your code that aren't tested at all, but having dogmatic enforcement of a particular coverage percentage is just going to lead to people gaming the system by writing "tests" that don't test anything. – Daniel Mann Nov 20 '15 at 03:28
  • @DanielMann one of my previous teams used code coverage to alert them that code could be deleted. If our acceptance tests could all pass without the code - it wasn't needed. – Fenton Nov 23 '15 at 10:53
  • @ELE, are you working with vNext build system or XMAL build? – Vicky - MSFT Nov 24 '15 at 10:02

2 Answers2

4

It is possible to control build result with code coverage percentage result in both vNext build system and XAML build.

In vNext build, you need to add the PowerShell step in the build definition, and run one PowerShell script to determine whether the build failed or succeed. Check this blog for the details of the PowerShell script: http://blogs.msdn.com/b/tfssetup/archive/2015/11/06/controlling-build-result-with-code-coverage-percentage-using-build-vnext.aspx

If you work with one XAML build, you need to create a custom build activity in which contains the logic to fail or pass a build based on code coverage result. Then include to use the build activity in the build definition. See: http://blogs.msdn.com/b/tfssetup/archive/2015/11/06/controlling-build-result-based-on-code-coverage-percentage-for-xaml-builds.aspx

Vicky - MSFT
  • 4,970
  • 1
  • 14
  • 22
0

My preferred method is to use the standard XAML build process in Azure DevOps pipeline. Use the code analysis task to fail the build if coverage is below a threshold.

See: https://learn.microsoft.com/en-us/archive/blogs/tfssetup/controlling-build-result-based-on-code-coverage-percentage-for-xaml-builds

David Rupe
  • 103
  • 1
  • 7