Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

alt text

like image 318
redsquare Avatar asked Jan 05 '11 09:01

redsquare


People also ask

What is TestContext in c#?

Each NUnit test runs in an execution context, which includes information about the environment as well as the test itself. The TestContext class allows tests to access certain information about the execution context.

What is Testmethod in NUnit?

The Test attribute is one way of marking a method inside a TestFixture class as a test. For backwards compatibility with previous versions of Nunit a test method may also be found if the first 4 letters are "test" regardless of case.

How do I use NUnit setup and TearDown?

In NUnit you can create Test Setup and Test Teardown by using [Setup] and [TearDown] attribute on a function. The above two function will get executed each time before execution of test and after execution of test. In writing Unit Test , Test SetUp and Test TearDown are very handy and useful.

Is NUnit a test runner?

The NUnit test runner contains the program entry point to run your tests. dotnet test starts the test runner using the unit test project you've created.


1 Answers

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.

like image 82
Sergey Berezovskiy Avatar answered Sep 20 '22 02:09

Sergey Berezovskiy