Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #457 from mmichaelis/master

Add trace method "skipped" to TestWatcher
  • Loading branch information...
commit a01caefa33a7f18356d916bbee4f02e6081d0485 2 parents 899527e + 00d830f
@dsaff dsaff authored
View
10 src/main/java/org/junit/rules/TestWatcher.java
@@ -54,6 +54,7 @@ public void evaluate() throws Throwable {
base.evaluate();
succeededQuietly(description, errors);
} catch (AssumptionViolatedException e) {
+ skipped(e, description);
throw e;
} catch (Throwable t) {
errors.add(t);
@@ -121,6 +122,15 @@ protected void failed(Throwable e, Description description) {
}
/**
+ * Invoked when a test is skipped due to a failed assumption.
+ *
+ * @param e
+ * @param description
+ */
+ protected void skipped(AssumptionViolatedException e, Description description) {
+ }
+
+ /**
* Invoked when a test is about to start
*
* @param description
View
30 src/test/java/org/junit/tests/experimental/rules/TestRuleTest.java
@@ -14,9 +14,11 @@
import java.util.List;
import org.junit.After;
+import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.TestName;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
@@ -457,6 +459,34 @@ public void methodOnFailure() {
assertEquals(1, result.getFailureCount());
}
+ public static class MethodOnSkippedTest {
+ private TestRule watchman= new TestWatcher() {
+ @Override
+ protected void skipped(AssumptionViolatedException e, Description description) {
+ log+= description + " " + e.getClass().getSimpleName();
+ }
+ };
+
+ @Rule
+ public TestRule getWatchman() {
+ return watchman;
+ }
+
+ @Test
+ public void nothing() {
+ Assume.assumeTrue(false);
+ }
+ }
+
+ @Test
+ public void methodOnSkipped() {
+ log= "";
+ Result result= JUnitCore.runClasses(MethodOnSkippedTest.class);
+ assertEquals(String.format("nothing(%s) AssumptionViolatedException", MethodOnSkippedTest.class.getName()), log);
+ assertEquals(0, result.getFailureCount());
+ assertEquals(1, result.getRunCount());
+ }
+
public static class MethodWatchmanTest {
private static String watchedLog;
Please sign in to comment.
Something went wrong with that request. Please try again.