How to skip TestFixtureSetup in NUnit

I am currently writing some integration tests in NUnit that require some customization that is done inside the method [TestFixtureSetUp]

. In case something goes wrong during installation (for example, unable to connect to the server), what is the correct way to abandon the method and pass it to NUnit? I would just throw an exception, or is there a specific NUnit method to call?

+3


source to share


1 answer


  • If the methods you call throw exceptions on failure, just let them do so and the NUnit runner will catch them and terminate the unit device tests.

  • If you have a condition that should fail, use Assert()

    (like all of your other tests)

  • Otherwise, you can explicitly call the NUnit utility method Assert.Fail(message)

    .

    Most methods Assert

    allow you to identify a message that will help you diagnose the cause quickly.



You can also find this ShoudBe NUnit Wrapping Library which will simplify and type-check your assertions (replacing them with <expr>.ShouldBeXXX()

fluent extension methods) and remove the need to write error messages (it reports an expression that failed by reading the source code) + really helpful enumeration messages ... Since it's just a layer on top of NUnit, you can use it with existing NUnit tools like Reshaper, NUnit Runner, and CI. You can also safely add new ShouldBe unit tests to your old NUnit test suite, or combine it with NUnit features like parameterized unit tests .

+2


source







All Articles