문제

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).

alt text

도움이 되었습니까?

해결책

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;
            }
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top