KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > junit > runner > notification > RunListener


1 package org.junit.runner.notification;
2
3 import org.junit.runner.Description;
4 import org.junit.runner.Result;
5
6 /**
7  * <p>If you need to respond to the events during a test run, extend <code>RunListener</code>
8  * and override the appropriate methods. If a listener throws an exception while processing a
9  * 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) throws Exception JavaDoc {
40     }
41     
42     /**
43      * Called when all tests have finished
44      * @param result the summary of the test run, including all the tests that failed
45      */

46     public void testRunFinished(Result result) throws Exception JavaDoc {
47     }
48     
49     /**
50      * Called when an atomic test is about to be started.
51      * @param description the description of the test that is about to be run
52      * (generally a class and method name)
53      */

54     public void testStarted(Description description) throws Exception JavaDoc {
55     }
56
57     /**
58      * Called when an atomic test has finished, whether the test succeeds or fails.
59      * @param description the description of the test that just ran
60      */

61     public void testFinished(Description description) throws Exception JavaDoc {
62     }
63
64     /**
65      * Called when an atomic test fails.
66      * @param failure describes the test that failed and the exception that was thrown
67      */

68     public void testFailure(Failure failure) throws Exception JavaDoc {
69     }
70
71     /**
72      * Called when a test will not be run, generally because a test method is annotated
73      * with {@link org.junit.Ignore}.
74      * @param description describes the test that will not be run
75      */

76     public void testIgnored(Description description) throws Exception JavaDoc {
77     }
78
79 }
80
81
82
Popular Tags