Thursday, March 27, 2008

Running Tests and getting Code Coverage for our .NET projects.

As I wrote about a last week, the entire testing portion of Visual Studio is a mystery to me. I've never been a tester (for good reason) so I've really never spent the time to dig into Microsoft's offering. That was until I was forced to figure some stuff out, due to my new team wanting it.

From what I've found, TFS 2008 makes executing user's tests at build time very easy. All we had to do is add the following line to our Team Build project file and the magic happened. We had test results!!

<TestContainer include="$(OutDir)\Unit Tests.dll">

The code coverage was missing though so we had to track that down. Thanks to Benday, all we had to do is update our Team Project file again and magically, we had coverage results.


Of course this assumed our testrunconfig was setup for Code Coverage, which in our case it was.

So far, even a testing novice has found it pretty easy to get tests to run at build time. Feel free to share you experiences, both good and bad.


InnerWorkings said...

Unit testing in Team System is a tricky little fellow, but your team would be smart to get the basics of unit testing and testing patterns under your belts: dependency injection, using Test Stubs, using Mock Objects, using Shared Fixtures, and using Custom Assertions and Finder Methods.

Our company does 6 hours of basic VSTS training for .NET teams with up to 15 developers - it's available over the web, so check it out here if you're interested:

F Quednau said...

it doesn't work in my testing of TFS...
what I get is an extremely unhelpful
MSBUILD : warning MSB6006: "MSTest.exe" exited with code 1.

I added the RunConfigFile property in the topmost propertygroup and it is clear that this somehow causes the test part not to run...
somehow my solutionroot always looks empty, so maybe it's not catching the config file? Oh well, it's Friday.

Sachin said...

This error is occurring because you have VS2008 Professional on the build machine. Its only a base version of MSTests it does not include the ability to publish the test outcomes as Team Build is requesting.

You need to install Visual Studio 2008 Team System: Developer (or Tester) edition. Or you can install the full Team Suite on the build agent.

Hope that helps,

Mac Noland said...

Thanks Sachin. Yes, we ended up installing the Tester edition. Works like a charm.