CoreCLR's Blog

Archive for November, 2010

Executing Unit Tests on the Build server only

Posted by coreclr on November 18, 2010

We often have some Unit Tests/Integration Tests that we only want to execute when the tests are running on the TFS build server.
One solution is to put these tests in a separate solution, but this is annoying when doing refactoring. Having a separate solution is also a bad choice when we want to see our total code coverage results.
Another solution is to use the Test List feature in Visual Studio, but these Test Lists are just pure pain!

I would like to put an attribute on the TestMethod instead. As far as I know, this is not possible today.

So currently we have an environment variable on the build server, and then we use this method from our tests:

public static class TestUtils
{
	public static bool IsTestRunningOnBuildServer()
	{
		if (Environment.GetEnvironmentVariable("IS_TFS_SERVER", EnvironmentVariableTarget.Machine) != null)
		{
			return true;
		}
	   return false;
	}
}

Very simple, but it works.

Another solution is to use Test Categories in TFS2010:

http://www.edsquared.com/2009/09/25/Test+Categories+And+Running+A+Subset+Of+Tests+In+Team+Foundation+Server+2010.aspx

 

Advertisements

Posted in .NET | Tagged: | Leave a Comment »