question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ErrorCollector reports AssumptionViolatedException as failure when assumption is not meet multiple times.

See original GitHub issue

Sample 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:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kcooneycommented, Nov 16, 2016

After working on #1371 here’s what I think we should do

  • If the Callable passed to ErrorCollector.checkSucceeds() throws an AssumptionViolatedException then checkSucceeds() should wrap it with an AssertionError (with a useful message) before calling addError()
  • If an AssumptionViolatedException is passed to addError() then addError() should wrap it with an AssertionError (with a different message) before adding it to errors

I don’t like the idea of changing checkSucceeds() and/or addError() to throw exceptions if passed AssumptionViolatedException. Current users of these methods can reasonably expect that they will never throw an exception. In addition, if these methods did throw when encountering AssumptionViolatedException that would put a high burden on the callers. ErrorCollector rethrows any collected errors, so deferring the failure to verify() should be safe.

That being said, maybe addError() should throw a NullPointerException if you pass in a null (currently if you do this, MultipleFailureException.getMessage() will throw a NullPointerException). The caller shouldn’t have a problem avoiding passing in a null.

0reactions
kcooneycommented, Sep 30, 2016

I am actually now leaning to having ErrorCollector wrap AssumptionViolationException 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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found