JUnit4 测试类运行方法

测试类中不需要定义main函数,不能直接用 命令( java [classname] )来运行,以下摘录了JUnit4.8.2 cookbook 中的介绍:

 

 

How do you run your tests and collect their results?

Once you have tests, you'll want to run them. JUnit provides tools to define the suite to be run and to display its results. To run tests and see the results on the console, run this from a Java program:

org.junit.runner.JUnitCore.runClasses(TestClass1.class, ...);

or this from the command line, with both your test class and junit on the classpath:

java org.junit.runner.JUnitCore TestClass1.class [...other test classes...]

You make your JUnit 4 test classes accessible to a TestRunner designed to work with earlier versions of JUnit, declare a static method suite that returns a test.

public static junit.framework.Test suite() { 
    return new JUnit4TestAdapter(Example.class); 
}

你可能感兴趣的:(JUnit4)