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