Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nunit not running SetUp method in Visual Studio debug mode

I'm trying to debug into the tests after the setup method is called and the tests depend on the setup method being called.

I'm using Nunit 2.6.0.12051 testing a .Net 4.0 class library. The nunit Visual Studio project has a class marked with [SetUpFixture] and a method marked with [SetUp].

If I run the tests from the NUnit gui, I'm fairly certain the setup attrib'd class is called (because it isn't stopped at the setup class with a run-time error now) but I can't debug into it. If I try to change the settings to see Verbose Tracing, NUnit gui throws an unhandled excption.

If I run the tests from Visual Studio via Test View/Debug Selection, the break point at the setup method doesn't stop execution and the trace statements inside the method don't print in the debug window. So I'm certain the setup method isn't getting called.

While I could just change the setup class to be the base of all test classes, I only need the method run once.

Any help would be wonderful.

like image 785
DFBerry Avatar asked May 08 '12 02:05

DFBerry


People also ask

Does SetUp run before every test NUnit?

Inheritance. The SetUp attribute is inherited from any base class. Therefore, if a base class has defined a SetUp method, that method will be called before each test method in the derived class.


1 Answers

I just ran into this issue and eventually found this significant sentence from the NUnit SetUpFixture documentation:

"This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace."

Turned out my SetUpFixture class was in an entirely different namespace than my tests, so it wasn't being run.

like image 92
Laren Crawford Avatar answered Oct 26 '22 00:10

Laren Crawford