org.junit.Assume failure should ignore test and not fail it
spacanowski opened this issue · 4 comments
As it's stated in JUnit Assume documentation tests should be ignored and not failed. JUnitParamsRunner
behaves differently.
What version of JUnitParams and JUnit are you using, because I cannot reproduce it in the newest version?
Sorry, I should've been more specific.
junit: 4.12
JUnitParams: 1.1.0
It happens when you use Assume in @Before
and not @BeforeClass
. JUnit throws MultipleFailureException
which wraps multiple exceptions and not just AssumptionViolatedException
. I've tested it locally and adding
} catch (@SuppressWarnings("deprecation") MultipleFailureException e) {
for (Throwable failure : e.getFailures()) {
if (failure instanceof AssumptionViolatedException) {
eachNotifier.addFailedAssumption((AssumptionViolatedException) failure);
} else {
eachNotifier.addFailure(failure);
}
}
in ParameterisedTestMethodRunner.runMethodInvoker
fixes it. If you like I can create PR for it later today, but it's somewhat sketchy as MultipleFailureException
is deprecated, but JUnit itself still uses it.
We started from Intellij brand new maven project and we added below code
@RunWith(JUnitParamsRunner.class)
public class ExampleTest {
@Before
public void setUp() throws Exception {
Assume.assumeFalse(true);
}
@Test
@Parameters("AAA|3")
public void test(String text, Integer length) throws Exception { }
}
and our pom.xml file is just
<dependencies>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
and it works as expected - test is ignored. Can you create pull request in JUnitParams with failing test?
Never mind. I've found that someone in legacy project where it occurred was calling @Before
method in @After
method and it caused this problem. Sorry about that.