01: package org.junit.runner.notification;
02:
03: import org.junit.runner.Description;
04: import org.junit.runner.Result;
05:
06: /**
07: * <p>If you need to respond to the events during a test run, extend <code>RunListener</code>
08: * and override the appropriate methods. If a listener throws an exception while processing a
09: * test event, it will be removed for the remainder of the test run.</p>
10: *
11: * <p>For example, suppose you have a <code>Cowbell</code>
12: * class that you want to make a noise whenever a test fails. You could write:
13: * <pre>
14: * public class RingingListener extends RunListener {
15: * public void testFailure(Failure failure) {
16: * Cowbell.ring();
17: * }
18: * }
19: * </pre>
20: * </p>
21: *
22: * <p>To invoke your listener, you need to run your tests through <code>JUnitCore</code>.
23: * <pre>
24: * public void main(String... args) {
25: * JUnitCore core= new JUnitCore();
26: * core.addListener(new RingingListener());
27: * core.run(MyTestClass.class);
28: * }
29: * </pre>
30: * </p>
31: * @see org.junit.runner.JUnitCore
32: */
33: public class RunListener {
34:
35: /**
36: * Called before any tests have been run.
37: * @param description describes the tests to be run
38: */
39: public void testRunStarted(Description description)
40: throws Exception {
41: }
42:
43: /**
44: * Called when all tests have finished
45: * @param result the summary of the test run, including all the tests that failed
46: */
47: public void testRunFinished(Result result) throws Exception {
48: }
49:
50: /**
51: * Called when an atomic test is about to be started.
52: * @param description the description of the test that is about to be run
53: * (generally a class and method name)
54: */
55: public void testStarted(Description description) throws Exception {
56: }
57:
58: /**
59: * Called when an atomic test has finished, whether the test succeeds or fails.
60: * @param description the description of the test that just ran
61: */
62: public void testFinished(Description description) throws Exception {
63: }
64:
65: /**
66: * Called when an atomic test fails.
67: * @param failure describes the test that failed and the exception that was thrown
68: */
69: public void testFailure(Failure failure) throws Exception {
70: }
71:
72: /**
73: * Called when a test will not be run, generally because a test method is annotated
74: * with {@link org.junit.Ignore}.
75: * @param description describes the test that will not be run
76: */
77: public void testIgnored(Description description) throws Exception {
78: }
79: }
|