Tuesday, May 29, 2007

Team System Unit Tests and Deployment Items

Deployment files for unit tests

The files to be deployed with the tests have to be setup so that the tests can run successully on local machine and also on the build machine. Data files such as .cvs, .xml files etc. usually sits in the project directory along with everything all of the rest of my code files.

However the tests when run on the build machine fail because the files cannot be deployed to the "out" directory of the test results. I get a file IO exception – my .Xml file could not be located.

To make it work i had to do 2 things:

  • I select my data files in the solution explorer, and look at the properties window. I can then find the "Copy to Output Directory" setting and change it to "Copy always".

  • Secondly "DeploymentItem" attribute has to be applied to the items to be deployed other than the test assemblies.

You can use either absolute path or relative path to specify the location of the deployment files.

If you are using MSBuild and TeamCity for build, then you have to use a realtive path rather than the absolute path to make it work, because msbuild on the server uses relative paths as configured usually in the .build file.

To add a path for a deployment item please follow the following steps (as it is the easiet way to do so):


Select a test in the Test View window or in the Test Manager window.


Press F4.The Properties window for that test is displayed.


Click the Deployment Items property. An ellipsis (...) appears in the value column.


Click the ellipsis.The String Collection Editor dialog box is displayed.


Before the test is run, type a path to a folder or a file that you want to have copied to the test deployment folder. Press Enter and type additional paths to specify additional folders and files to be deployed.


Click OK.

No comments:

Post a Comment