views:

224

answers:

2

I am currently using the standard Microsoft Unit Test suite in VS 2008. ReSharper 4.5 is also installed. My unit tests rely on an TestInitialize method which pre-loads a data file. The path to this test data file will differ depending on if I run the unit test from within VS 2008 using the standard Ctrl-R + Ctrl-T command versus the Resharper unit test execution command.

How can my TestInitialize method know the correct path to the unit test data files?

Update:

The test data is sizable enough that I don't want to push it into a string so prefer to keep it as an external file. The file structure of my test project is that of the standard unit test project created with an MVC application. Under the root of the test project, a new folder was created called 'Test Data'. It's this folder I'd like to access regardless of test runner.

+1  A: 

Could you not create the test data from scratch in your test suite initialisation routine? This wouldn't rely on it being at a specific location and it would be safe from inadvertent tampering.

ChrisF
+1  A: 

You're saying the test file's location will differ depending on the test runner, so I assume it's included in the project and copied together with the dll's.

string path = AppDomain.CurrentDomain.BaseDirectory;

This will get you the folder where you're executing the test from.

[Edit]

In Visual Studio.

Resharper -> Options -> Tools -> Unit Testing -> Run Results from: Specified Folder (or change the project output folder of your test project)

Where you can specify the folder of your test data, or relative to the specified folder.

Mikael Svenson