I know the answer may differ for each test framework. But for the ones you know, what should happen?
views:
93answers:
4In NUnit, you have TestFixtureSetUp
which runs only once before all tests in the fixture run and SetUp
which runs before each test method is run.
This naturally depends on the frameworks, and for the concrete answers to this you should check the relevant documentation.
Set up methods for tests, or fixtures are useful, but they should not be abused. If unit tests have complex set up methods you could argue they are more so integration tests, and thus should be refactored. A complex test set up is a code smell. On the other hand, set up methods used wisely can reduce duplication and make tests more readable and maintainable.
In MSTest you have TestInitializeAttribute
When run in a load test, the method marked with this attribute will run once for every virtual user iteration in the test. If you need to do initialization operations once, that apply to the entire test, use the ClassInitializeAttribute.
AssemblyInitializeAttribute
is run once for all tests in all classes.
In junit4 you have annotations available to mark both kind of setup/teardown methods. Here is the summary:
- running setup before each test suite use
@BeforeClass
- running tear down after each test suite use
@AfterClass
- running setup before each test method in your suite use
@Before
- running tear down after each test method in your suite use
@After