9

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.

1
  • For lack of a technical answer, and having looked into this from a design perspective. I'm going to remove the attribs and just call the method from the tests that depend on it (90% of the tests). The method will also have a flag that only does the work if it hasn't previously been done. This will allow each test to be easily readable in terms of what happens - instead of making something go find the setup method or base class. Commented May 8, 2012 at 12:18

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

I just noticed the same when using the latest NUnit from NuGet (2.6). The [Setup] method is not run before the [Test] -methods.

I don't know why they changed this quite significant part of NUnit, but I fixed it for my purposes by going back to version 2.5.10 which does run [Setup] before [Test].

2 Comments

I've just encountered this so it's still an issue in 2.6.2
Note that [SetUp] is case-sensitive, at least that solved the issue for me in v2.6.4, where I was inadvertently using a different [Setup] attribute that was presumably added by NUnit or VS.
1

I had this issue too but installing the latest version of the test runner (TestDriven.NET in my case) fixed it. It wasn't an NUnit issue for me.

Comments

0

I just ran into a similar issue. My unit test was not calling setup either. After reading the NUnit doc. referred in the top answer, I figured my solution was extremely simple. In very simple terms, I was missing the "Setup". Realised after reading the doc.

*Example from NUnit SetUpFixture doc mentioned in top answer.

[SetUp] 
RunBeforeAnyTests()
{
//
}

----------------------------------------------------

// this was my fixed up code
// simply added [Setup] and boom, bob is your uncle.

[SetUp] 
public void Setup()
{
    readChoice.Reset();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.