I have a test where I do not need to run the SetUp
method (attributed with [SetUp]
) before running the test. I need the SetUp
method to be run for other tests.
Is there a different attribute that can be used or a non-attribute-based way to achieve this?
IgnoreAttribute (NUnit 2.0) The ignore attribute is an attribute to not run a test or test fixture for a period of time. The person marks either a Test or a TestFixture with the Ignore Attribute. The running program sees the attribute and does not run the test or tests.
In unit testing frameworks, Setup is called before each and every unit test within your test suite.
This attribute is used inside a TestFixture to provide a common set of functions that are performed just before each test method is called. SetUp methods may be either static or instance methods and you may define more than one of them in a fixture.
Setup methods (both types) are called on base classes first, then on derived classes. If any setup method throws an exception, no further setups are called. Teardown methods (again, both types) are called on derived classes first, then on the base class.
You could also add a category and inspect the category list in your setup:
public const string SKIP_SETUP = "SkipSetup";
[SetUp]
public void Setup(){
if (!CheckForSkipSetup()){
// Do Setup stuff
}
}
private static bool CheckForSkipSetup() {
ArrayList categories = TestContext.CurrentContext.Test
.Properties["_CATEGORIES"] as ArrayList;
bool skipSetup = categories != null && categories.Contains( SKIP_SETUP );
return skipSetup ;
}
[Test]
[Category(SKIP_SETUP)]
public void SomeTest(){
// your test code
}
You should create a new class for that test which has only the setup (or lack of setup) that it needs.
Alternatively, you could unfactor the setup code into a method that all the other tests call, but I don't recommend this approach.
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