[英]TFS Build Machine Test method errors out on build machine
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: 在TFS生成计算机上,当我运行单元测试时,出现以下错误:
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: 当我查看TFS中的放置文件夹时,我看到我的文件已部署到以下文件夹中:
\\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
? 当我的单元测试在TFS构建计算机上运行时,是否可以查看已部署的Common\\MySpecialFiles
的文件?
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()
. 对于诸如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. 我建议存储到此网络的路径,以共享配置文件或数据库,以便无需代码推送即可对其进行更新。
Why not put the location of the files in an appSettings item in the app.config/web.config file? 为什么不将文件的位置放在app.config / web.config文件的appSettings项目中? 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. 否则,您必须在运行测试之前将当前目录设置为\\ MyBuildServer \\ Builds \\ MyFolder \\ MySolution_20130116.5 ,这可能会以其他方式影响您的测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.