3

我想根据我在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
         }
    }
4

1 回答 1

0

您可以使用Assert.Ignore()像 Matthew 状态。Assert.Inconclusive()如果您想对结果进行不同的分类,也可以使用。

这个问题/答案有点相似:Programmatically skip an nunit test

于 2013-08-22T22:20:25.030 回答