我有一个单元测试,查看包含在我的测试项目中的文本文件。我不得不采取这条路线,因为我似乎无法正确复制C#字符串中的特殊字符,用户正在进入原始数据本身(某些其他系统)。TFS 2010中的单元测试资产Build
单元测试在排列部分中读取文件的内容,然后对内容执行操作以确保事情按计划进行。
本地,测试运行正常 - 零问题。
我们运行TFS2010 Build,并且每次测试都会失败,因为在构建服务器上运行测试时未找到文本文件本身。
我的文件是目前在测试项目本身所谓的“资产”,文本文件的属性是一个目录:
- 生成操作:内容
- 复制到输出目录:复制始终
测试代码是
[TestMethod]
public void Broken_First_Token_Ok_Second_Returns_Full_String()
{
string rawText = string.Empty;
// load the broken translation
using (StreamReader reader = new StreamReader(@"Assets\BrokenTranslation.txt")){
rawText = reader.ReadToEnd();
}
string expected = rawText;
string actual = [Some code that should return the proper values]
Assert.AreEqual(expected, actual, "Failed to return proper match");
}
有什么我错过了?
你有没有试过通过DeploymentItem属性使你的测试可用的文本文件?本博客文章描述了如何以及为什么要使用它:http://luisfsgoncalves.wordpress .com/2011/05/31/unit-tests-with-dependencies-on-team-foundation-server/ – 2012-08-17 15:30:56
@IanGilroy,你想添加一个答案?辉煌的链接,完全是我在找的。 – reallyJim 2012-08-17 16:18:08