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 the screengrab file name to the test name, but it is always null (see attached image). The _context private variable has a TestName, but this is useless to me!

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

alt text

+8
c # unit-testing nunit
source share
3 answers

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

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

+3
source share

I had the same problem. This happened when, in the TearDown method, I executed a method that actually had to break

[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 this your case?

UPDATE: now I looked at the screenshot, so this is not your case :)

0
source share

Same problem with R # test runner. Just load the NUnit sources and add a workaround to the TestAdapter so that it works with r #

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

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


All Articles