1

我正在使用 mstest.exe 执行我的测试用例,当我从 vs 运行这个测试用例时,它们运行良好,但是当我使用 ms-build 从巡航控制运行它们时,它们给了我异常,他们无法读取 application.config . 我的意思是我创建了一个从 app.config 读取值的类。它有一个将端口号读取为字符串并将其转换为 int 的字段,使用 VS 它是工作文件,但使用 Ms 构建它会显示 ArgumentNullException 异常。

那么我如何指定 mstest 使用特定的 app.config 文件。

提前致谢。

4

1 回答 1

1

在 app.config 属性上,设置Copy to Output Directory=Copy always

如果测试在TestDeploymentDir使用下运行DeploymentItemAttribute

[TestMethod]
[DeploymentItem("app.config")]

在 Visual Studio 2012 或更高版本中,您可以使用.runsettings更多部署选项。

在 Visual Studio 2010 中:

Test菜单 > Edit Test Settings> Local>Deployment选项卡 > 检查Enable deploymentAdd file指向 app.config

于 2012-05-11T15:20:39.253 回答