Visual Studio unit testing - how to access external files?

I have data files used as input for my unit tests. These files are quite large, and I do not want to copy them every time when unit tests are performed. Tests are run without deployment. So I can just put them in a folder under my solution and ... how to get the path to my solution (or the source code of the project) when the unit test is running?

+7
unit-testing visual-studio
source share
3 answers

Since you can run a test project in different ways (TD.NET, Visual Studio, R #, etc.), the path used to reference the tests may change.

For this reason, I insert test files into my test assembly and get them out of there.

+3
source share

You can use:

Assembly.GetExecutingAssembly().Location 

in your tests to get the build path containing unit tests.

0
source share

Simple, make file locations customizable (and verifiable).

Then either install it in a unit test code, or install it through some configuration file.

0
source share

All Articles