blob: edfb97c543f73f6f7c5a0294ba081cbff66eb09f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
package org.junit.runner;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
/**
* A <code>Result</code> collects and summarizes information from running multiple
* tests. Since tests are expected to run correctly, successful tests are only noted in
* the count of tests that ran.
*/
public class Result implements Serializable {
private static final long serialVersionUID = 1L;
private AtomicInteger fCount = new AtomicInteger();
private AtomicInteger fIgnoreCount= new AtomicInteger();
private final List<Failure> fFailures= Collections.synchronizedList(new ArrayList<Failure>());
private long fRunTime= 0;
private long fStartTime;
/**
* @return the number of tests run
*/
public int getRunCount() {
return fCount.get();
}
/**
* @return the number of tests that failed during the run
*/
public int getFailureCount() {
return fFailures.size();
}
/**
* @return the number of milliseconds it took to run the entire suite to run
*/
public long getRunTime() {
return fRunTime;
}
/**
* @return the {@link Failure}s describing tests that failed and the problems they encountered
*/
public List<Failure> getFailures() {
return fFailures;
}
/**
* @return the number of tests ignored during the run
*/
public int getIgnoreCount() {
return fIgnoreCount.get();
}
/**
* @return <code>true</code> if all tests succeeded
*/
public boolean wasSuccessful() {
return getFailureCount() == 0;
}
private class Listener extends RunListener {
@Override
public void testRunStarted(Description description) throws Exception {
fStartTime= System.currentTimeMillis();
}
@Override
public void testRunFinished(Result result) throws Exception {
long endTime= System.currentTimeMillis();
fRunTime+= endTime - fStartTime;
}
@Override
public void testFinished(Description description) throws Exception {
fCount.getAndIncrement();
}
@Override
public void testFailure(Failure failure) throws Exception {
fFailures.add(failure);
}
@Override
public void testIgnored(Description description) throws Exception {
fIgnoreCount.getAndIncrement();
}
@Override
public void testAssumptionFailure(Failure failure) {
// do nothing: same as passing (for 4.5; may change in 4.6)
}
}
/**
* Internal use only.
*/
public RunListener createListener() {
return new Listener();
}
}
|