tags:

views:

239

answers:

2

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 give some useful things like ignore and explicit but that not quiet what I need.

Thanks

+4  A: 

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." );
     }
}

or

[TestFixtureSetUp]
public void FixtureSetUp()
{
     if (!TestHelper.SimulationFilesExist())
     {
         Assert.Ignore( "Simulation files are not installed.  Omitting fixture." );
     }
}
tvanfosson
Thanks for the quick response! But this will result in a failed test, not really what I want. The fact that test did not executed does not mean it should indicate failed (in my case).
Koen
No. Assert.Fail will result in a failed test. Assert.Ignore() does exactly what you want it to do. It causes the test to be ignored at runtime. Quoting from the docs: "The Assert.Ignore method provides you with the ability to dynamically cause a test or suite to be ignored at runtime."
tvanfosson
You're right tvanfosson. When you only run the testfixture it will indicate failed, but when you run a bunch of testfixtures all together the testfixture will be omitted and the end result is SUCCESS!! Thanks a lot.
Koen
Depending on which version of the NUnit framework you're using, there is also Assert.Inconclusive. This will also result in a successful result, but flag that those tests may fail under other conditions.
Richard J Foster
+1  A: 

NUnit also gives you the option to supply a Category attribute. Depending on how you are launching your tests, it may be appropriate to flag all the tests that require the simulator with a known category (e.g. [Category("RequiresSimulationSoftware")]). Then from the NUnit Gui you can choose to exclude certain categories. You can do the same thing from the NUnit command line runner (specify /exclude:RequiresSimulationSoftware if applicable).

Hope this (or the previous answer by tvanfosson) helps.

Richard J Foster
Hey, I thought of this solution. The downside of this solution is that it is caller specific. We sometimes execute the tests from within VStudio and the other time from a script. Both should be altered and maintained.
Koen