【发布时间】:2015-09-16 00:24:24
【问题描述】:
按照程序概述here 和here,我能够设置一个TestRunParameter 并在运行时在Unit 测试中访问它。然后,我在编码的 UI 测试中重复了完全相同的过程,但无法访问属性。
我的 .runsettings 文件:
<RunSettings>
<TestRunParameters>
<Parameter name="webAppUrl" value="http://localhost" />
</TestRunParameters>
</RunSettings>
我的测试方法:
[TestMethod]
public void MyTest1()
{
// This throws an error because Properties["webAppUrl"] is null
string webAppUrl = TestContext.Properties["webAppUrl"].ToString();
// etc...
}
Coded UI 测试是否需要额外配置才能访问这些运行时属性?
编辑:
我注意到在单元测试的上下文中,TestContext 是Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestContextImplementation。在 Coded UI 测试中,TestContext 是Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext。
【问题讨论】:
-
好像是在 Visual Studio 2013 的更新中添加的 stackoverflow.com/a/33362632/155892
-
我相信该功能只是片状。我在可靠地访问 unit 测试中的属性时遇到问题。有时我的 runsettings 文件中的属性存在,有时它们不存在。
标签: visual-studio coded-ui-tests azure-devops