NUnit TestContext.CurrentContext 空引用异常

发布于 2024-10-23 18:45:37 字数 726 浏览 1 评论 0原文

今天早上我一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若水般的淡然安静女子 2024-10-30 18:45:37

好吧......在没有成功深入研究这个异常之后,我发现了这篇文章: 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?

玩物 2024-10-30 18:45:37

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文