01: package jfb.tst.tools.activitymgr;
02:
03: import junit.framework.AssertionFailedError;
04: import junit.framework.Test;
05: import junit.framework.TestCase;
06: import junit.framework.TestListener;
07: import junit.framework.TestResult;
08: import junit.framework.TestSuite;
09:
10: public class AllTestsWithLogger extends AllTests {
11:
12: public static void main(String[] args) {
13: TestResult result = new TestResult();
14: AllTestListener testListener = new AllTestListener();
15: result.addListener(testListener);
16: long startTime = System.currentTimeMillis();
17: TestSuite suite = (TestSuite) suite();
18: suite.run(result);
19: long endTime = System.currentTimeMillis();
20: long runTime = endTime - startTime;
21: System.out.println("Test suite terminated.");
22: System.out.println(" time elapsed :" + runTime);
23: System.out.println(" nb tests :"
24: + (testListener.getOk() + testListener.getKo()));
25: System.out.println(" tests ok :" + testListener.getOk());
26: System.out.println(" tests ko :" + testListener.getKo());
27: }
28:
29: }
30:
31: class AllTestListener implements TestListener {
32: boolean testFailed = false;
33: int ok;
34: int ko;
35:
36: public void addError(Test test, Throwable t) {
37: log(" ERROR : " + ((TestCase) test).getName() + ", t=" + t);
38: testFailed = true;
39: }
40:
41: public void addFailure(Test test, AssertionFailedError t) {
42: addError(test, t);
43: }
44:
45: public void endTest(Test test) {
46: if (testFailed)
47: ko++;
48: else
49: ok++;
50: log(" TEST STATUS :" + (testFailed ? "FAILURE" : "SUCCESS"));
51: }
52:
53: public void startTest(Test test) {
54: log("BEGIN TEST '" + ((TestCase) test).getName() + "'");
55: // Réinitialisation
56: testFailed = false;
57: }
58:
59: private void log(String s) {
60: System.out.println(s);
61: }
62:
63: /**
64: * @return Returns the ok.
65: */
66: public int getOk() {
67: return ok;
68: }
69:
70: /**
71: * @return Returns the ko.
72: */
73: public int getKo() {
74: return ko;
75: }
76:
77: }
|