NUnit TestContext.CurrentContext null reference exception

五迷三道 提交于 2019-12-12 11:38:26

问题


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)
    {
    }
}

回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/5363635/nunit-testcontext-currentcontext-null-reference-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!