I am writing unit tests in visual studio 2010.
For test some functionality, I have added a folder with testfiles.
I need to get this folder programmatically without a hard path in a string.
The folder contains in <projectDirectory>/TestFiles
I have tried to use AppDomain.CurrentDomain.BaseDirectory
.
This will only work if I run my unit tests with resharper.
result is <projectDirectory>/bin/debug
so I can easily go to TestFiles.
If I am running test with visual studio, the BaseDirectory is:
<sameFolderAsSolutionFile>\TestResults\<username>_<pcname> <datatime>\Out
I have moved my solution file to another folder. So my projects aren't in the same folder as my solution file.
Example:
<sameFolderAsSolutionFile> = C:\SolutionFiles
<projectDirectory> = C:\Projects\MyProject
Can someone tell me how to get the path to my test-files without using a hardcoded string?
EDIT
I haven't found a solution yet.
Visual Studio is using another build folder for testing.
So everything what is normally builded into the bin folder will be builded into another folder for the test.
MY TEMP-SOLUTION
I have added a App.config file in my test project.
In this configuration file I have added a setting with the required path to the test files:
<appSettings>
<add key="TestFiles" value="C:\Projects\MyProject\TestFiles"/>
</appSettings>
You can copy this folder into the deployment folder of the unit tests with the DeploymentItem attribute.