问题描述
我们的解决方案中有一些集成测试.要运行这些测试,必须在开发人员 PC 上安装模拟软件.然而,该软件并非安装在每台开发人员 PC 上.如果没有安装仿真软件,则跳过这些测试,否则==>空引用异常.
We've got some integration tests in our solution. To run these tests, simulation software must be installed on the developer PC. This software is, however, not installed on every developer PC. If the simulation software is not installed, these tests should be skipped, otherwise ==> NullRefException.
我现在正在寻找一种有条件忽略"的方法.用于测试/测试装置.类似的东西
I'm now seeking for a way to do a "conditional ignore" for tests/testfixtures.Something like
if(simulationFilesExist)
do testfixture
else skip testfixture
NUnit 提供了一些有用的东西,比如忽略和显式,但这并不是我所需要的.
NUnit gives some useful things like ignore and explicit but that's not quiet what I need.
推荐答案
在您的测试或夹具设置方法中使用一些代码来检测是否安装了模拟软件并调用 Assert.Ignore() 如果不是.
Use some code in your test or fixture set up method that detects if the simulation software is installed or not and calls Assert.Ignore() if it isn't.
[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
.
In NUnit 3.0 and higher you have to use OneTimeSetUp
attribute instead of TestFixtureSetUp
.
这篇关于根据条件忽略测试或测试夹具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!