Reputation: 137534
My project has some unit tests. They all depend on some external service, over which I have no control. This service is frequently down (recall Twitter circa 2008). Currently, if the service is down, then the tests fail, and the continuous integration server won't build. I resent this. I'd like to ignore the tests that depend on this setup, printing a warning.
[BeforeScenario]
try
{
connect(server)
}
catch (Exception x)
{
throw new Exception(String.Format("Failed to connect to server {0}", server), x);
}
How can I do this? I happen to be using SpecFlow today, but I'd also like to know how to do this from NUnit.
Below is what I have currently. It's okay. The tests are ignored, but the build still fails.
[BeforeScenario]
try
{
connect(server)
}
catch (Exception x)
{
throw new SpecFlowCancelTests(String.Format("Failed to connect to server {0}", server), x);
}
Upvotes: 2
Views: 488
Reputation: 62484
You can use either Assert.Inconclusive("message") or Assert.Ignore() utility methods:
The Assert.Inconclusive method indicates that the test could not be completed with the data available. It should be used in situations where another run with different data might run to completion, with either a success or failure outcome.
The Assert.Ignore method provides you with the ability to dynamically cause a test or suite to be ignored at runtime. It may be called in a test, setup or fixture setup method. We recommend that you use this only in isolated cases. The category facility is provided for more extensive inclusion or exclusion of tests or you may elect to simply divide tests run on different occasions into different assemblies.
Useful links: - What is the Inconclusive Test Condition?
Upvotes: 3