【发布时间】:2013-12-10 14:32:28
【问题描述】:
我在我的TestCleanup 方法中检查TestContext.CurrentTestOutcome,以便在测试未通过时执行操作(在这种情况下,测试使用 Selenium 来运行一个网站,如果测试我正在保存屏幕截图不通过)。
private static TestContext _testContext;
private static IWebDriver _driver;
[ClassInitialize]
public static void SetupTests(TestContext testContext)
{
_testContext = testContext;
_driver = new FirefoxDriver();
}
[TestCleanup]
public void TeardownTest()
{
if (_testContext.CurrentTestOutcome != UnitTestOutcome.Passed)
{
var fileName = Path.Combine(
Environment.CurrentDirectory,
string.Format("{0}.{1}.gif", _testContext.FullyQualifiedTestClassName, _testContext.TestName));
((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(fileName, ImageFormat.Gif);
Console.WriteLine("Test outcome was {0}, saved image of page to '{1}'", _testContext.CurrentTestOutcome, fileName);
}
}
这在使用 ReSharper 的本地开发 PC 上运行时效果很好,但在我们的构建服务器(使用 TeamCity)上,UnitTestOutcome 始终为 Unknown,尽管 TeamCity 报告它们已通过。
documentation on MSDN 不是很有帮助。什么会导致此值设置为 Unknown?
【问题讨论】:
-
在本地运行时,测试如何运行?锐器? Visual Studio 的内置 MSTest 工具?
-
@Arran - 我们正在使用 Resharper 在本地运行测试。我已经相应地更新了我的问题。
标签: c# selenium-webdriver mstest teamcity-8.0