Skip to content

Commit

Permalink
TestWatcher.skipped(): Make test fail
Browse files Browse the repository at this point in the history
To show problem of skipped not ignoring failures in skipped-method here is the test - which fails.
  • Loading branch information
mmichaelis committed Oct 1, 2012
1 parent 129a5f7 commit a982920
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.results.PrintableResult;
import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
Expand All @@ -35,6 +36,29 @@ public void neitherLogSuccessNorFailedForViolatedAssumption() {
is("starting finished "));
}

public static class TestWatcherSkippedThrowsExceptionTest {
@Rule
public TestRule watcher= new TestWatcher() {
@Override
protected void skipped(AssumptionViolatedException e, Description description) {
throw new RuntimeException("watcher failure");
}
};

@Test
public void fails() {
throw new AssumptionViolatedException("test failure");
}
}

@Test
public void testWatcherSkippedThrowsException() {
PrintableResult result= testResult(TestWatcherSkippedThrowsExceptionTest.class);
assertThat(result, failureCountIs(2));
assertThat(result, hasFailureContaining("test failure"));
assertThat(result, hasFailureContaining("watcher failure"));
}

public static class FailingTest {
private static StringBuilder watchedLog= new StringBuilder();

Expand Down

0 comments on commit a982920

Please sign in to comment.