ErrorCollector reports AssumptionViolatedException as failure when assumption is not meet multiple times.
See original GitHub issueSample test:
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
public class SampleTest {
@Rule
public ErrorCollector errorCollector = new ErrorCollector();
@Test
public void test() throws Exception {
errorCollector.checkSucceeds(() -> {
doSth();
return null;
});
errorCollector.checkSucceeds(() -> {
doSth();
return null;
});
}
private void doSth() {
Assume.assumeTrue(false);
}
}
Expected result: test ignored. Actual: test failed.
Working as expected (ie. test results as ignored) when:
@Test
public void test() throws Exception {
errorCollector.checkSucceeds(() -> {
doSth();
return null;
});
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
AssumptionViolatedException (JUnit API)
An assumption exception with the given actual value and a matcher describing the expectation that failed. Method Summary. Methods inherited from class org.junit ......
Read more >Why my JUnit error collector is not reporting the error?
Although my assertion is failing, error is not reported in JUnit. But I am getting the "error" message in console. @Rule public ErrorCollector...
Read more >AssertJ - fluent assertions java library - GitHub Pages
Specify whether or not date/time parsing is to be lenient for AssertJ default ... as we can fix all reported errors at once...
Read more >Index (JUnit API) - Javadoc.io
AssumptionViolatedException : An assumption exception with the given actual ... ErrorCollector: Adds a failure to the table if matcher does not match value...
Read more >Static method in class org.junit.runner.Request - RICE CS
addFailedAssumption (AssumptionViolatedException) - Method in class ... ErrorCollector: Adds a failure to the table if matcher does not match value .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After working on #1371 here’s what I think we should do
Callable
passed toErrorCollector.checkSucceeds()
throws anAssumptionViolatedException
thencheckSucceeds()
should wrap it with anAssertionError
(with a useful message) before callingaddError()
AssumptionViolatedException
is passed toaddError()
thenaddError()
should wrap it with anAssertionError
(with a different message) before adding it toerrors
I don’t like the idea of changing
checkSucceeds()
and/oraddError()
to throw exceptions if passedAssumptionViolatedException
. Current users of these methods can reasonably expect that they will never throw an exception. In addition, if these methods did throw when encounteringAssumptionViolatedException
that would put a high burden on the callers.ErrorCollector
rethrows any collected errors, so deferring the failure toverify()
should be safe.That being said, maybe
addError()
should throw aNullPointerException
if you pass in anull
(currently if you do this,MultipleFailureException.getMessage()
will throw aNullPointerException
). The caller shouldn’t have a problem avoiding passing in anull
.I am actually now leaning to having
ErrorCollector
wrapAssumptionViolationException
in another exception if it is the only collected exception. That way, if you have any collected errors you’ll get a failure (not a skipped test)