我想忽略某些基于我在 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
}
}
最佳答案
您可以像 Matthew 所说的那样使用 Assert.Ignore()
。如果您想对结果进行不同的分类,您也可以使用 Assert.Inconclusive()
。
这个问题/答案有点相似:Programmatically skip an nunit test
关于c# - 选择性忽略 NUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18391248/