This post is inspired by a problem we had in our TFS2008 build environment, I am not sure if it applies to the 2005 version of MSBuild.

The problem

Say you are running tests in your team builds, and you have configured your build so they can run on a Developer desktop as well as on a build server. By default, using Microsoft’s targets, tests are not run during a Desktop Build. This means that a build can pass when run locally but fail, or give partial success on the server, due to test errors. We had a scenario where some tests were “Not runnable” in our Test Container. Which resulted in failed builds.

The reason is that MSTest returns the error code 1 if there are tests that are not runnable.

To test the behaviour locally we wanted our tests to run during the Desktop Build, so we could have a faster debug cycle when working with this problem.

Solution:

By looking in the Microsoft.TeamFoundation.Build.targets file, we see what dependencies the test targets have.

Here is a list starting from the Test target. If a target has a dependency it is located above the target. If a target results in the execution of MSBuild on different targets it is represented by the content in the column to the right column.

BeforeTest;

CoreTest; (CoreTest starts the project file again but targets RunTest)

ComputeConfigurationList;

RunTest (RunTest starts the project file again but targets TestConfiguration)

BeforeTestConfiguration;

ResolveTestFilesForEndToEndIteration

CoreTestConfiguration;

AfterTestConfiguration;

TestConfiguration

AfterTest;

The target marked red in the above table is not run during Desktop Builds, and is the only one that doesn’t work in Desktop environments. This means that the entire suite of test targets stops at that target. The CoreTestConfiguration target depends on the ResolveTestFilesForEndToEndIteration target, and the CoreTestConfiguration runs the actual tests. The ResolveTestFilesForEndToEndIteration target looks like the following.