001: package org.junit.runner;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import org.junit.runner.notification.Failure;
007: import org.junit.runner.notification.RunListener;
008:
009: /**
010: * A <code>Result</code> collects and summarizes information from running multiple
011: * tests. Since tests are expected to run correctly, successful tests are only noted in
012: * the count of tests that ran.
013: */
014: public class Result {
015: private int fCount = 0;
016: private int fIgnoreCount = 0;
017: private List<Failure> fFailures = new ArrayList<Failure>();
018: private long fRunTime = 0;
019: private long fStartTime;
020:
021: /**
022: * @return the number of tests run
023: */
024: public int getRunCount() {
025: return fCount;
026: }
027:
028: /**
029: * @return the number of tests that failed during the run
030: */
031: public int getFailureCount() {
032: return fFailures.size();
033: }
034:
035: /**
036: * @return the number of milliseconds it took to run the entire suite to run
037: */
038: public long getRunTime() {
039: return fRunTime;
040: }
041:
042: /**
043: * @return the {@link Failure}s describing tests that failed and the problems they encountered
044: */
045: public List<Failure> getFailures() {
046: return fFailures;
047: }
048:
049: /**
050: * @return the number of tests ignored during the run
051: */
052: public int getIgnoreCount() {
053: return fIgnoreCount;
054: }
055:
056: /**
057: * @return <code>true</code> if all tests succeeded
058: */
059: public boolean wasSuccessful() {
060: return getFailureCount() == 0;
061: }
062:
063: private class Listener extends RunListener {
064: @Override
065: public void testRunStarted(Description description)
066: throws Exception {
067: fStartTime = System.currentTimeMillis();
068: }
069:
070: @Override
071: public void testRunFinished(Result result) throws Exception {
072: long endTime = System.currentTimeMillis();
073: fRunTime += endTime - fStartTime;
074: }
075:
076: @Override
077: public void testStarted(Description description)
078: throws Exception {
079: fCount++;
080: }
081:
082: @Override
083: public void testFailure(Failure failure) throws Exception {
084: fFailures.add(failure);
085: }
086:
087: @Override
088: public void testIgnored(Description description)
089: throws Exception {
090: fIgnoreCount++;
091: }
092: }
093:
094: /**
095: * Internal use only.
096: */
097: public RunListener createListener() {
098: return new Listener();
099: }
100: }
|