KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > TextRunnerTest


1 package junit.tests;
2
3 import junit.framework.*;
4 import java.io.*;
5
6 public class TextRunnerTest extends TestCase {
7     public TextRunnerTest(String JavaDoc name) {
8         super(name);
9     }
10     
11     public void testFailure() throws Exception JavaDoc {
12         execTest("junit.tests.Failure", false);
13     }
14
15     public void testSuccess() throws Exception JavaDoc {
16         execTest("junit.tests.Success", true);
17     }
18
19     public void testError() throws Exception JavaDoc {
20         execTest("junit.tests.BogusDude", false);
21     }
22     
23     void execTest(String JavaDoc testClass, boolean success) throws Exception JavaDoc {
24         String JavaDoc java= System.getProperty("java.home")+File.separator+"bin"+File.separator+"java";
25         String JavaDoc cp= System.getProperty("java.class.path");
26         //use -classpath for JDK 1.1.7 compatibility
27
String JavaDoc [] cmd= { java, "-classpath", cp, "junit.textui.TestRunner", testClass};
28         Process JavaDoc p= Runtime.getRuntime().exec(cmd);
29         InputStream i= p.getInputStream();
30         int b;
31         while((b= i.read()) != -1)
32             ; //System.out.write(b);
33
assertTrue((p.waitFor() == 0) == success);
34     }
35         
36
37 }
Popular Tags