2

I have a junit integration test that runs on our build machine, and calls an external server. We use a gating build - so code doesn't make it in to the main branch unless we get 100% of tests passing

Occasionally, the external server goes down for a while, and the test fails, but with a definitive exception that I can catch. I really don't want the test to fail the build, therefore blocking code getting in - but I also would prefer it's not marked as "passed". So I want to sort of mark it as a warning, ignored, or indeterminate result. This would be ideal:

@Test
public void someTest() 
{
    try
    {
        do whatever
    }
    catch (ServerDownException theException)
    {
         junit.markThisTestAsIgnored();           <----  something like this
    }
}
Darren Oakey
  • 2,894
  • 3
  • 29
  • 55

2 Answers2

0

found it -

throw new AssumptionViolationException( "skipping test because xxx is down");
Darren Oakey
  • 2,894
  • 3
  • 29
  • 55
0

One option is to set a category(stress category for example).

Check out this link:

https://github.com/junit-team/junit4/wiki/categories

If you want, you can put the @Ignore rule:

https://dzone.com/articles/allowing-junit-tests-pass-test

Regards