Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

TestWatcher.skipped(): Make test fail

To show problem of skipped not ignoring failures in skipped-method here is the test - which fails.
  • Loading branch information...
commit a982920ee8036d001aa4a223a2521be28681ec27 1 parent 129a5f7
Mark Michaelis authored
24 src/test/java/org/junit/tests/experimental/rules/TestWatcherTest.java
@@ -10,6 +10,7 @@
10 10 import org.junit.Rule;
11 11 import org.junit.Test;
12 12 import org.junit.experimental.results.PrintableResult;
  13 +import org.junit.internal.AssumptionViolatedException;
13 14 import org.junit.rules.TestRule;
14 15 import org.junit.rules.TestWatcher;
15 16 import org.junit.runner.Description;
@@ -35,6 +36,29 @@ public void neitherLogSuccessNorFailedForViolatedAssumption() {
35 36 is("starting finished "));
36 37 }
37 38
  39 + public static class TestWatcherSkippedThrowsExceptionTest {
  40 + @Rule
  41 + public TestRule watcher= new TestWatcher() {
  42 + @Override
  43 + protected void skipped(AssumptionViolatedException e, Description description) {
  44 + throw new RuntimeException("watcher failure");
  45 + }
  46 + };
  47 +
  48 + @Test
  49 + public void fails() {
  50 + throw new AssumptionViolatedException("test failure");
  51 + }
  52 + }
  53 +
  54 + @Test
  55 + public void testWatcherSkippedThrowsException() {
  56 + PrintableResult result= testResult(TestWatcherSkippedThrowsExceptionTest.class);
  57 + assertThat(result, failureCountIs(2));
  58 + assertThat(result, hasFailureContaining("test failure"));
  59 + assertThat(result, hasFailureContaining("watcher failure"));
  60 + }
  61 +
38 62 public static class FailingTest {
39 63 private static StringBuilder watchedLog= new StringBuilder();
40 64

0 comments on commit a982920

Please sign in to comment.
Something went wrong with that request. Please try again.