简体   繁体   中英

Visual Studio unit testing - how to access external files?

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?

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

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

You can use:

Assembly.GetExecutingAssembly().Location

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM