KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > junit > runner > Result


1 package org.junit.runner;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.junit.runner.notification.Failure;
7 import org.junit.runner.notification.RunListener;
8
9 /**
10  * A <code>Result</code> collects and summarizes information from running multiple
11  * tests. Since tests are expected to run correctly, successful tests are only noted in
12  * the count of tests that ran.
13  */

14 public class Result {
15     private int fCount= 0;
16     private int fIgnoreCount= 0;
17     private List JavaDoc<Failure> fFailures= new ArrayList JavaDoc<Failure>();
18     private long fRunTime= 0;
19     private long fStartTime;
20
21     /**
22      * @return the number of tests run
23      */

24     public int getRunCount() {
25         return fCount;
26     }
27
28     /**
29      * @return the number of tests that failed during the run
30      */

31     public int getFailureCount() {
32         return fFailures.size();
33     }
34
35     /**
36      * @return the number of milliseconds it took to run the entire suite to run
37      */

38     public long getRunTime() {
39         return fRunTime;
40     }
41
42     /**
43      * @return the {@link Failure}s describing tests that failed and the problems they encountered
44      */

45     public List JavaDoc<Failure> getFailures() {
46         return fFailures;
47     }
48
49     /**
50      * @return the number of tests ignored during the run
51      */

52     public int getIgnoreCount() {
53         return fIgnoreCount;
54     }
55
56     /**
57      * @return <code>true</code> if all tests succeeded
58      */

59     public boolean wasSuccessful() {
60         return getFailureCount() == 0;
61     }
62
63     private class Listener extends RunListener {
64         @Override JavaDoc
65         public void testRunStarted(Description description) throws Exception JavaDoc {
66             fStartTime= System.currentTimeMillis();
67         }
68
69         @Override JavaDoc
70         public void testRunFinished(Result result) throws Exception JavaDoc {
71             long endTime= System.currentTimeMillis();
72             fRunTime+= endTime - fStartTime;
73         }
74
75         @Override JavaDoc
76         public void testStarted(Description description) throws Exception JavaDoc {
77             fCount++;
78         }
79
80         @Override JavaDoc
81         public void testFailure(Failure failure) throws Exception JavaDoc {
82             fFailures.add(failure);
83         }
84
85         @Override JavaDoc
86         public void testIgnored(Description description) throws Exception JavaDoc {
87             fIgnoreCount++;
88         }
89     }
90
91     /**
92      * Internal use only.
93      */

94     public RunListener createListener() {
95         return new Listener();
96     }
97 }
98
Popular Tags