AutoTester213
AutoTester213

Reputation: 2871

TFS 2017 - how to run a build with code coverage?

Hi I'm trying to run a build with code coverage, I am using Visual Stuido 2017 enterprise I have tried to enable the code coverage in VS but if i click on Edit build definition in team explorer it opens the build definition in TFS.

Upvotes: 0

Views: 4547

Answers (1)

ColinM
ColinM

Reputation: 2681

Apologies for the delay in posting this as an answer.

As a prerequisite to using Code Coverage, the first thing to do is to install Visual Studio Enterprise on the build agent (Which you have already done). Following this, you must then update your builds to specify that Code Coverage is/should be enabled.

To enable code coverage, ensure you have included a Visual Studio Test task (or any equivalent which supports Coverage) in your build definition.

Once you have added the Test task, you'll want to configure this task and set your test assemblies, for this you can use an absolute path to point to a DLL file, or use wildcards like I do here

$(build.sourcesDirectory)\Source\Tests**\Release*Test*.dll

This says that in my sources directory I have a folder called Source, and inside that is a Tests folder which contains all of my unit tests. Then in each Unit Tests folder I use a wildcard to say "any folder at all that contains a Release folder", look inside and take the DLL which has 'Test' in its name.

So now that the testing assemblies are gathered, you can tick the checkbox that says "Code Coverage Enabled", and you're good to go.

I will edit this post later today to include screenshots of my own personal VSTS builds.

Upvotes: 5

Related Questions