选择性忽略NUnit测试

时间:2013-08-22 21:36:47

标签: c# nunit

我想根据我在TestFixtureSetUp期间从配置文件中提取的数据忽略某些测试。有没有办法忽略基于参数运行测试?

[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.
    }

}

如果我们正在测试的帐户是付费帐户,则测试应运行正常,否则,该方法将抛出异常。

是否会对属性[Ignore(ReallyIgnore = isPaidAccount )]进行扩展?或者我应该在方法中写这个并运行2个单独的测试用例,例如。

    public void Message_Without_Template_Is_Sent()
    {
         if(isPaidAccount)
         {
              //test for return value here
         }
         else
         {
              //test for exception here
         }
    }

1 个答案:

答案 0 :(得分:0)

您可以像马修州一样使用Assert.Ignore()。如果您想以不同方式对结果进行分类,也可以使用Assert.Inconclusive()

此问题/答案略有相似:Programmatically skip an nunit test

相关问题