Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a junit test that is skipped because of an assumption failure is not reported as skipped?

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)

like image 356
FrVaBe Avatar asked Sep 28 '10 16:09

FrVaBe


1 Answers

While previous answers are good on their own, I'd like to address the "WHY" question.

The problem stemmed from the fact how tests failed / ignored were counted. When assumptions were added, usual counts were kinda skewered (assumption can IGNORE the tests half-way through it's run).

Tools runners had problems with that as well, causing messy reporting. See here for Surefire dev conversation with JUnit people, and here for related Eclipse bug.

Right now this ain't a problem in Maven, and it should not be in newer Eclipses. I use STS based on eclipse.buildId = 2.9.2.201205071000-RELEASE and I still experience this behaviour.

EDIT: reference type links did not work.

like image 163
LAFK says Reinstate Monica Avatar answered Nov 15 '22 00:11

LAFK says Reinstate Monica