当前位置:K88软件开发文章中心网站服务器框架junit → 文章内容

JUnit - API

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-25 14:24:24

译的这个结果4int errorCount() 获取被检测出错误的数量5Enumeration errors() 返回错误的详细信息6int failureCount() 获取被检测出的失败的数量7void run(TestCase test) 运行 TestCase8int int runCount() 获得运行测试的数量9void startTest(Test test) 声明一个测试即将开始10void stop() 标明测试必须停止在 C:\ > JUNIT_WORKSPACE 路径下创建一个名为 TestJunit3.java 的类。 import org.junit.Test;import junit.framework.AssertionFailedError;import junit.framework.TestResult;public class TestJunit3 extends TestResult { // add the error public synchronized void addError(Test test, Throwable t) { super.addError((junit.framework.Test) test, t); } // add the failure public synchronized void addFailure(Test test, AssertionFailedError t) { super.addFailure((junit.framework.Test) test, t); } @Test public void testAdd() { // add any test } // Marks that the test run should stop. public synchronized void stop() { //stop the test here }}接下来,在 C:\ > JUNIT_WORKSPACE 路径下创建一个名为 TestRunner3.java 的类来执行测试案例。import org.junit.runner.JUnitCore;import org.junit.runner.Result;import org.junit.runner.notification.Failure;public class TestRunner3 { public static void main(String[] args) { Result result = JUnitCore.runClasses(TestJunit3.class); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } System.out.println(result.wasSuccessful()); }} 用 javac 编译 Test case 和 Test Runner 类 C:\JUNIT_WORKSPACE>javac TestJunit3.java TestRunner3.java现在运行 Test Runner 它将运行在 Test Case 类中定义并提供的测试样例。 C:\JUNIT_WORKSPACE>java TestRunner3检查输出结果。 trueTestSuite 类下面定义的是 org.junit.TestSuite 类:public class TestSuite extends Object implements TestTestSuite 类是测试的组成部分。它运行了很多的测试案例。TestSuite 类的一些重要方法列式如下: 序号方法和描述1void addTest(Test test) 在套中加入测试。2void addTestSuite(Class<? extends TestCase> testClass) 将已经给定的类中的测试加到套中。3int countTestCases() 对这个测试即将运行的测试案例进行计数。4String getName() 返回套的名称。5void run(TestResult result) 在 TestResult 中运行测试并收集结果。6void setName(String name) 设置套的名称。7Test testAt(int index) 在给定的目录中返回测试。8int testCount() 返回套中测试的数量。9static Test warning(String message) 返回会失败的测试并且记录警告信息。在 C:\ > JUNIT_WORKSPACE 路径下创建一个名为 JunitTestSuite.java 的类。 import junit.framework.*;public class JunitTestSuite { public static void main(String[] a) { // add the test's in the suite TestSuite suite = new TestSuite(TestJunit1.class, TestJunit2.class, TestJunit3.class ); TestResult result = new TestResult(); suite.run(result); System.out.println("Number of test cases = " + result.runCount()); }}用 javac 编译 Test suit C:\JUNIT_WORKSPACE>javac JunitTestSuite.java现在运行 Test Suit C:\JUNIT_WORKSPACE>java JunitTestSuite检查输出结果。 No of Test Case = 1Test Case Name = testAddUpdated Test Case Name = testNewAddNumber of test cases = 3

上一页  [1] [2] 


JUnit - API