开发者

Nunit - TestContext.CurrentContext.Test not working

I am using nunit 2.5.9.10348 and trying to extract the current test name in the TearDown event so I can assign a screengrab filename the test name however it is always null (see the attached image). The private _context variable does have开发者_运维问答 the TestName however this is no use to me!

Has anyone had success using this new TestContext functionality (from 2.5.7).

Nunit - TestContext.CurrentContext.Test not working


From your screenshot I see that _context has keys "TestName" and "Properties". But TestAdapter looks for keys "Test.Name" for Name and "Test.Properties" for Properties. So, there is something wrong with TestContext initialization (I think wrong data was put to Remoting.Messaging.CallContext).

After a little investigation (see comments): NUnit tests should run by NUnit testig environment for Context to be available.


I had the same issue. It occurred when in a TearDown method I executed method, which actually was to make the teardown

[TearDown]
public void CleanUp()
{
    TestContext.CurrentContext.Test.FullName; //!=null
    someClassInstance.DoTearDown();
}

class SomeClass
{
     public void DoTearDown()
     {
          TestContext.CurrentContext.Test.FullName; //==null
     }
}

I have no idea why, but it seemed so. Is it your case?

UPDATE: Now I looked at the screenshot, so it's not your case :)


Same issue with R# test runner. Just downloaded NUnit sources and added a workaround in TestAdapter to make it work with r#

        public string Name
        {
            get
            {
                return (_context["Test.Name"] ?? _context["TestName"]) as string;
            }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜