Null exception NUnit TestContext.CurrentContext

This morning I played with watiN / Nunit to capture a screenshot of failed user interface tests. However, I run NRE when accessing the Nunits TestContext.CurrentContext ...

Any ideas on 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) { } } 
+4
source share
2 answers

Well ... after unsuccessfully diving into this exception, I came across this post: http://www.barebonescoder.com/2010/10/nunit-and-the-new-testcontext-class/

Running my test using the nunit test sheet is successful ... now, to figure out how to make this work with the resharpers test runner?

+5
source

Is this CurrentContext property or Result property NULL? Perhaps the result has not been set because the test is not yet complete. I am working on a project in work using WatiN / NUnit, and I was able to use the TestContext class without problems, but I must say that I did not notice the state of the Result property.

If the Result property is NULL, try moving the browser initialization to the TestSetUp method and capturing the screen in TestTearDown before deleting the browser instance.

+1
source

Source: https://habr.com/ru/post/1344390/


All Articles