Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MSTest to find my test data files?

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...

like image 297
Johan Driessen Avatar asked Dec 11 '09 08:12

Johan Driessen


People also ask

How do I run a MSTest unit test?

To run MSTest unit tests, specify the full path to the MSTest executable (mstest.exe) in the Unit Testing Options dialog. To call this dialog directly from the editor, right-click somewhere in the editor and then click Options.

Which is better NUnit or MSTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.


2 Answers

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")); } 
like image 101
Daniel Elliott Avatar answered Sep 24 '22 03:09

Daniel Elliott


This post answers this question: MSTest copy file to test run folder

like image 34
Matt Salmon Avatar answered Sep 22 '22 03:09

Matt Salmon