Thursday, 22 August 2013

Selective Ignore of NUnit tests

Selective Ignore of NUnit tests

I want to ignore certain tests based on data I pulled from a configuration
file during the TestFixtureSetUp. Is there a way to ignore running a test
based on parameters?
[TestFixture]
public class MessagesTests
{
private bool isPaidAccount;
[TestFixtureSetUp]
public void Init () {
isPaidAccount = ConfigurationManager.AppSettings["IsPaidAccount"]
== "True";
}
[Test]
//this test should run only if `isPaidAccount` is true
public void Message_Without_Template_Is_Sent()
{
//this tests an actual web api call.
}
}
If account we are testing with is a paid account, the test should run
fine, if not, the method will throw an exception.
Would there be an extension of the attribute [Ignore(ReallyIgnore =
isPaidAccount )]? Or should I write this inside the method and run 2
separate test cases for eg.
public void Message_Without_Template_Is_Sent()
{
if(isPaidAccount)
{
//test for return value here
}
else
{
//test for exception here
}
}

No comments:

Post a Comment