NUnit: Global setup fixture not used when fixture to run is specified on command line
I have a unit test assembly, using NUnit, that contains thousands of tests in vario开发者_开发知识库us 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.
精彩评论