Skip to main content
added 223 characters in body
Source Link
Bizhan
  • 17.2k
  • 11
  • 67
  • 108

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or not.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 

Edit:

Beware that the TestContext may be automatically generated if it's required.

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or not.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or not.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 

Edit:

Beware that the TestContext may be automatically generated if it's required.

fixed misprint
Source Link
ChessMax
  • 2.3k
  • 1
  • 17
  • 20

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or nownot.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or now.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or not.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 
An explanation added
Source Link
ChessMax
  • 2.3k
  • 1
  • 17
  • 20

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or now.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 
using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // Do some setup to avoid error } 

Having a reference to nunit framework doesn't mean that test is actually running. For example in Unity when you activate play mode tests the nunit references are added to the project. And when you run a game the references are exist, so UnitTestDetector would not work correctly.

Instead of checking for nunit assembly we can ask nunit api to check is code under executing test now or now.

using NUnit.Framework; // ... if (TestContext.CurrentContext != null) { // nunit test detected // Do some setup to avoid error } 
Source Link
ChessMax
  • 2.3k
  • 1
  • 17
  • 20
Loading