textrunnertest.java
来自「Java测试工具Junit3.8.1官方发布源码」· Java 代码 · 共 61 行
JAVA
61 行
package junit.tests.runner;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PrintStream;import junit.framework.TestCase;import junit.framework.TestResult;import junit.framework.TestSuite;public class TextRunnerTest extends TestCase { public void testFailure() throws Exception { execTest("junit.tests.framework.Failure", false); } public void testSuccess() throws Exception { execTest("junit.tests.framework.Success", true); } public void testError() throws Exception { execTest("junit.tests.BogusDude", false); } void execTest(String testClass, boolean success) throws Exception { String java= System.getProperty("java.home")+File.separator+"bin"+File.separator+"java"; String cp= System.getProperty("java.class.path"); //use -classpath for JDK 1.1.7 compatibility String [] cmd= { java, "-classpath", cp, "junit.textui.TestRunner", testClass}; Process p= Runtime.getRuntime().exec(cmd); InputStream i= p.getInputStream(); int b; while((b= i.read()) != -1) ; //System.out.write(b); assertTrue((p.waitFor() == 0) == success); if (success) assertEquals(junit.textui.TestRunner.SUCCESS_EXIT, p.exitValue()); else assertEquals(junit.textui.TestRunner.FAILURE_EXIT, p.exitValue()); } public void testRunReturnsResult() { PrintStream oldOut= System.out; System.setOut(new PrintStream ( new OutputStream() { public void write(int arg0) throws IOException { } } )); try {
TestResult result= junit.textui.TestRunner.run(new TestSuite()); assertTrue(result.wasSuccessful()); } finally { System.setOut(oldOut);
} } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?