NUnit TestContext.CurrentContext 空引用异常
今天早上我一直在使用 watiN / Nunit 来捕获失败的 UI 测试的屏幕截图。但是,我在访问 Nunits TestContext.CurrentContext 时遇到了 NRE...
关于我做错了什么有什么想法吗?
[TestFixture]
class SomePageTest
{
[Test]
[STAThread]
public void Page_IsAvailable()
{
var browser = new SomePage();
Assert.IsTrue(browser.ContainsText("Something"));
if (TestContext.CurrentContext.Result.Status == TestStatus.Failed)
{
browser.CaptureWebPageToFile(@"X:\location\" + TestContext.CurrentContext.Test.FullName);
}
}
}
public class SomePage: IE
{
public static string SomePageUrl = "http://somepage.com/someurl";
public SomePage() : base(SomePageUrl)
{
}
}
I've been playing around this morning with watiN / Nunit to capture a screenshot on failed UI tests. However, I'm running into NRE's when accessing Nunits TestContext.CurrentContext...
Any ideas as to what I'm doing wrong?
[TestFixture]
class SomePageTest
{
[Test]
[STAThread]
public void Page_IsAvailable()
{
var browser = new SomePage();
Assert.IsTrue(browser.ContainsText("Something"));
if (TestContext.CurrentContext.Result.Status == TestStatus.Failed)
{
browser.CaptureWebPageToFile(@"X:\location\" + TestContext.CurrentContext.Test.FullName);
}
}
}
public class SomePage: IE
{
public static string SomePageUrl = "http://somepage.com/someurl";
public SomePage() : base(SomePageUrl)
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧......在没有成功深入研究这个异常之后,我发现了这篇文章: http://www.barebonescoder.com/2010/10/nunit-and-the-new-testcontext-class/
从 nunit 的测试运行程序运行我的测试是成功的......现在弄清楚如何做到这一点与 resharpers 测试运行程序合作?
Well...after no success diving into this exception I came across this post: http://www.barebonescoder.com/2010/10/nunit-and-the-new-testcontext-class/
Running my test from nunit's test runner is successful...now to figure out how to make this work with resharpers test runner?
CurrentContext 属性还是 Result 属性为 NULL?可能是因为测试尚未完成而尚未设置结果。我正在使用 WatiN/NUnit 处理项目,并且我已经能够毫无问题地使用 TestContext 类,但我不得不说我没有注意到 Result 属性的状态。
如果 Result 属性为 NULL,则可以尝试将浏览器的初始化移至 TestSetUp 方法中,并在处理浏览器实例之前将屏幕捕获放入 TestTearDown 中。
Is it the CurrentContext property or the Result property that is NULL? It may be that the Result hasn't been set because the test has not yet completed. I'm working on project in work using WatiN/NUnit and I've been able to use the TestContext class without any problems, but I have to say I've not noticed the state of the Result property.
If the Result property is NULL, then maybe try moving the initialisation of the browser into a TestSetUp method and perform the screen capture into the TestTearDown before disposing of the browser instance.