c# - How to fail a TestFixtureSetup in NUnit -


i'm writing integration tests in nunit require setup being done inside of [testfixturesetup] method. in event goes wrong during setup (e.g. not connect server), what's proper way fail method , convey nunit? throw exception, or there specific nunit method call?

  • if methods calling throw exceptions on failure let them , nunit runner catch them , fail fixture unit tests.

  • if have condition should trigger failure use assert() (like other tests)

  • otherwise, can explicitly call nunit utility method assert.fail(message).

    most assert methods allow define message diagnose cause.

you might find shoudbe nunit wrapper library useful simplify , type check assertions (replacing them <expr>.shouldbexxx() fluent extension methods) , removing need write failure messages (it reports expression failed reading source code) + useful enumeration messages. because it's layer on top of nunit, can use existing nunit tools reshaper, nunit runner , ci. can safely add new shouldbe unit tests old nunit test suite or combine nunit features parameterised unit tests.


Comments