views:

56

answers:

1

I use junit assumptions to decide whether to run a test or not.
Tests where the assumption fails are ignored/skipped by the junit framework.

I wonder why skipped tests are not reported as 'skipped'?

Please have a look at the example:

import static org.junit.Assert.fail;
import org.junit.Assume;
import org.junit.Test;

public class AssumptionTest {

    @Test
    public void skipAssumptionFailureTest() {
        Assume.assumeTrue("foo".equals("bar"));
        fail("This should not be reached!");
    }
}

Running this test in a maven project results in:

Running AssumptionTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec

I would prefer to have this test reported as 'skipped'. Is there any chance to achieve this?

(junit 4.8.1; maven 2.2.1; java 1.6.0_21)

+1  A: 

You can't do this out-of-the-box as the only way to skip tests is with the @Ignore annotation. However, I found a blog post which might just be what you are looking for:

dogbane
Thanks for the response. Too bad that this does not work out of the box. Implementing a custom runner will not work for me - I normally already use a custom runner (SpringJUnit4ClassRunner) in my tests which I will not extend. I would have preferred a build in solution.
K. Claszen