KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > BasicTestCase


1 package org.exoplatform.test;
2
3 import junit.framework.TestCase;
4
5 public class BasicTestCase extends TestCase {
6   private static int testNumber_ = 1 ;
7   protected int counter_ ;
8
9   public BasicTestCase() {
10   }
11   
12   public BasicTestCase(String JavaDoc name) {
13     super(name);
14   }
15   
16   protected int getTestNumber() {
17     return testNumber_ ;
18   }
19
20   protected void setTestNumber(int num) {
21     testNumber_ = num ;
22   }
23   
24   protected int getCounter() {
25     return counter_ + 1;
26   }
27
28   protected void runTest() throws Throwable JavaDoc {
29     long t = System.currentTimeMillis() ;
30     long firstRun = 0 ;
31     int testNum = getTestNumber() ;
32     System.out.println(getDescription());
33     System.out.println("Test Case: " + getName() + "()" );
34     for(counter_= 0; counter_ < testNum; counter_++) {
35       super.runTest() ;
36       if (counter_ == 0) {
37         firstRun = System.currentTimeMillis() - t;
38       }
39     }
40     t = System.currentTimeMillis() - t;
41     System.out.println("End Test Case: run " + getName() + "() " +
42                        getTestNumber() + " time in " + t +
43                        "ms, first run: " + firstRun + "ms, " +
44                        "average: " + t/testNum+ "ms\n");
45   }
46   
47   protected static void info(String JavaDoc s) {
48     System.out.println(" INFO: " + s);
49   }
50
51   protected static void error(String JavaDoc s) {
52     System.out.println("ERROR: " + s);
53   }
54
55   protected String JavaDoc getDescription() {
56     return "Run test " + getClass().getName() ;
57   }
58 }
59
Popular Tags