Reputation: 14148
Here is my unit test code:
[TestMethod]
public void GetMyAttachmentTest()
{
var files = Directory.GetFiles(
Directory.GetCurrentDirectory() + "/Common/MyFiles/", "*.*");
.... do some thing with the files...
}
On TFS build machine, when I run my unit test, I am getting the following error:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Builds\4\30 my folder v1.0\myfolder1\TestResults\SCMTFSService_MyBuildServer 2013-01-16 18_06_52_Any CPU_Release\Out\Common\MySpecialFiles\'.
When I look into the drop folder in TFS, I see that my files are deployed into the following folder:
\\MyBuildServer\Builds\MyFolder\MySolution_20130116.5\Common\MySpecialFiles
Inside my unit test code, I get my files as follows:
var files = Directory.GetFiles(
Directory.GetCurrentDirectory() + "/Common/MySpecialFiles/", "*.*");
Is there a way when my unit test runs on TFS build machine that it can look into the files in the deployed Common\MySpecialFiles
?
Upvotes: 0
Views: 527
Reputation: 44275
The question is a bit vague. In the past, I've had issues with unit tests executing in temp locations. This can be problematic with dynamic paths such as GetCurrentDirectory()
. When the the temp directory changes/clears, files can be "lost".
Instead of using a dynamic path, setup a network share with appropriate permissions. I recommend storing the path to this network share a config file or the DB so that it can be updated without a code push.
Upvotes: 1
Reputation: 7484
Why not put the location of the files in an appSettings item in the app.config/web.config file? That will make it easy to change it to match your environment whether it's local, a build server or a deployed environment.
Otherwise, you will have to set the current directory to \MyBuildServer\Builds\MyFolder\MySolution_20130116.5 before running your test and that will probably impact your tests in other ways.
Upvotes: 0