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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With