CoreCLR's Blog

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: