简体   繁体   English

TFS构建机器测试方法错误在构建机器上

[英]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.

相关问题 Selenium测试无法在运行TFS 2018构建代理的构建计算机上与IE11一起运行 - Selenium test fails to run with IE11 on build machine running TFS 2018 build agent TFS单元测试在开发人员计算机上通过但在构建计算机上失败 - TFS unit tests passing on developer machine but failing on build machine 调用System.Reflection.Assembly.Load时,TFS 2010单元测试在构建计算机上失败 - TFS 2010 Unit Test fails on build machine when calling System.Reflection.Assembly.Load 如何获得要在构建机器上构建的NUnit测试项目? - How do you get an NUnit test project to build on a build machine? TFS 构建测试结果 - TFS Build Test Results 为什么这个单元测试在我的机器上传递但在构建服务器上失败? - Why does this unit test pass on my machine but fail on the build server? 使用TeamCity设置构建计算机 - Setting up a Build machine with TeamCity 在本地计算机上构建的C#dll与TFS构建服务器之间的区别 - Difference between C# dll built on local machine & TFS build server 属性设置在开发机中有效,但在Build Server中不起作用 - Property setting works in development machine but not in Build Server Watin测试在TeamCity构建机器上不起作用 - Watin Tests do not work on TeamCity build machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM