views:

184

answers:

4

I have data files used as input to my unit tests. These files are quite big and I don't want to copy them each time unit tests are executed. Tests are executed without deployment. So I can just put them into folder under my solution, and... how to obtain path to my solution (or test project source code) when unit test is executing?

A: 

You can use:

Assembly.GetExecutingAssembly().Location

in your tests to get the path of the assembly containing the unit tests.

Erik Öjebo
It gives location of the unit test's binary file, but I still don't know path to the solution's root.
skevar7
+1  A: 

Due to the different ways you can run a test project - TD.NET, VisStudio, R# etc. The path the tests are running at can change.

For this reason, I embed test needed files in my test assembly and draw them out from there.

Kindness,

Dan

Daniel Elliott
A: 
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

Will give you the folder you probably want. If not I am sure you can infer things from here.

RichardOD
A: 

Simple, make the location of the files configurable (and testable).

Then either, set it in the unit testing code or set it thru some config file.

Ray