nunit - 根据条件忽略测试或TestFixture

标签 nunit

我们的解决方案中有一些集成测试。要运行这些测试,必须在开发人员PC上安装仿真软件。但是,并不是每个开发人员PC上都安装此软件。如果未安装仿真软件,则应跳过这些测试,否则==> NullRefException。

我现在正在寻找一种对测试/测试夹具进行“条件忽略”的方法。
就像是

如果(simulationFilesExist)
做测试治具
否则跳过testfixture

NUnit提供了一些有用的东西,例如忽略和显式,但是并不能使我需要的东西安静下来。

谢谢

最佳答案

在测试或夹具设置方法中使用一些代码来检测是否已安装模拟软件,如果未安装,则调用Assert.Ignore()

[SetUp]
public void TestSetUp() 
{
     if (!TestHelper.SimulationFilesExist())
     {
         Assert.Ignore( "Simulation files are not installed.  Omitting." );
     }
}

要么

[TestFixtureSetUp]
public void FixtureSetUp()
{
     if (!TestHelper.SimulationFilesExist())
     {
         Assert.Ignore( "Simulation files are not installed.  Omitting fixture." );
     }
}

NUnit 3.0及更高版本中,您必须使用OneTimeSetUp属性而不是TestFixtureSetUp

关于nunit - 根据条件忽略测试或TestFixture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1594293/

相关文章:

c# - 如何为单元测试伪造 HttpContext?

c# - 在 NUnit 测试中使用最小起订量模拟 HttpContext.Current

c# - 具有无参数构造函数的 NUnit TestFixture

c# - 使用 NUnit 测试弹出窗口

asp.net-mvc-3 - 如何实现ViewModel类的依赖注入(inject)?

testing - SpecFlow 未在工具->选项->SpecFlow->TestRunnerTool 中列出 NUnit

NUnit 与 Windows Phone 7

nunit - 单元测试时模型不会自动验证

c# - 如何使用多个数据源进行单元测试?

c# - AppDomain.UnhandledException 处理程序不会在单元测试中触发