Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current TestContext in TeamCity NUnit runner

Tags:

teamcity

nunit

In NUnit, it is possible to get the current test with NUnit.Framework.TestContext.CurrentContext. When I run tests on my local machine, this is correctly populated during testing. However, when pushed to a dev server running TeamCity, this data structure has some problem causing errors. These errors occur when accessing context.Test.FullName, context.Test.Name, and context.Result. For example, with the following code:

var name = NUnit.Framework.TestContext.CurrentContext.Test.Name;

this exception occurs, but only when TeamCity is running the tests:

TearDown method failed. TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
--TearDown
   at NUnit.Framework.TestContext.TestAdapter.get_Name()

Is TeamCity not populating the TestContext or is there a correct way to get this data?

like image 467
mjibson Avatar asked Nov 13 '22 06:11

mjibson


1 Answers

Best guess: this is not possible because TeamCity is not populating the TestContext data structures. Nor can it, because the setters in NUnit are not public. For this functionality to work, NUnit likely needs to be modified.

In order to get around this limitation, we wrote our own test runner with a custom data structure to indicate test failure (which was the principal purpose of this).

like image 103
mjibson Avatar answered Jan 04 '23 03:01

mjibson