29
votes

I have a few tests that need to be fed with external data from excel files. The files are included in the test project, and in Visual Studio, I have edited the test settings file (Local.testsettings) to deploy the data files. This makes it work fine i VS.

We are, however, also running continous integration with TeamCity, and in TeamCity this doesn't work. My data files are unavailable to the test. Seems that the tests are run from a temporary folder named "C:\TeamCity\buildAgent\temp\buildTmp\ciuser_AS40VS6 2009-12-11 09_40_17\Out", and the data files are not copied there.

I have tried changing the build action for the data files to "Resource" and setting copy to output dir to "Always", but that didn't help.

Does anyone know how to make this work?

I am running Visual Studio 2010 beta 2 and TeamCity 4.5.5, which is why I'm running MSTest in the first place, and not NUnit...

3
I also have been using the resource workaround, but why do we need it in the first place? How does the TC build differ from that on our dev PCs??Luke Puplett

3 Answers

21
votes

I get round this by adding my data files (in my case usually XML) as embedded resources and I extract them from the test assembly.

[TestInitialize]
public void InitializeTests()
{
    var asm = Assembly.GetExecutingAssembly();
    this.doc = new XmlDocument();
    this.doc.Load(asm.GetManifestResourceStream("TestAssembly.File.xml"));
}
4
votes
0
votes

The accepted answer is technically correct. However, from my experience, I find that the embedding files as resources requires an additional step of remembering to set the property "Embedded Resource". This becomes a challenge when you have a large number of data files. Also, with increasing number of data files, the size of the unit test assembly keeps growing . In my case, I had over 500MB of test data files and packing all them into the assembly was not a good idea.

What is the alternative?

Let the data files remain as they are. Do not use DeploymentItemAttribute, do not use embedded resources. Please refer my proposed solution How do I make a data file available to unit tests?