I have a unit test assembly, using NUnit, that contains thousands of tests in various namespaces and fixtures.
I want to run some global setup before any tests in my assembly are run (configuring Trace listeners). I can do this by creating a [SetUpFixture]
in the global namespace.
This works fine when running all tests e.g.:nunit.exe testassembly.exe
However, if I specify a fixture to test, then the global setup is not run, e.g.:nunit.exe testassembly.exe /fixture=MyTests
How do I provide global setup that is always run before any tests in an assembly are run?
UPDATE:
Note that the console test runner will work fine using the /run
option, i.e. global setup is run even when only a particular test fixture is run. I'm after a solution for the GUI test runner.
Charlie Poole suggested an alternative in the NUnit discussion forum.
The recommended workaround is to include all setup and teardown at the fixture level using using [TestFixtureSetup]
and [TestFixtureTearDown]
.
Global setup and teardown can be achieved like this by using a base class for the test fixtures to share code between fixtures. For global setup meant to be run once only before any fixture, a flag can be used to prevent it being executed multiple times.
P.S. The /fixture option is deprecated theses days.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With