Skip to content

Instantly share code, notes, and snippets.

@alinush
Created August 23, 2014 06:18
Show Gist options
  • Save alinush/d937094f314771eb1218 to your computer and use it in GitHub Desktop.
Save alinush/d937094f314771eb1218 to your computer and use it in GitHub Desktop.
Java JUnit TestWatcher
@Rule
public TestWatcher watchman = new TestWatcher() {
@Override
protected void starting(final Description description) {
String methodName = description.getMethodName();
String className = description.getClassName();
className = className.substring(className.lastIndexOf('.') + 1);
System.out.println("\n * Running " + className + "::" + methodName);
}
@Override
protected void failed(Throwable e, Description description) {
someTestsFailed = true;
}
};
@alinush
Copy link
Author

alinush commented Aug 23, 2014

Add this to any of your JUnit test case classes if you want notifications about tests failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment