import junit.framework.*;
import java.util.*;
public class SimpleTest extends TestCase {
public SimpleTest(String name) {
super(name);
}
/**
* 写一个测试方法断言期望的结果
* JUnit推荐的做法是以test作为待测试的方法的开头,这样这些方法可以被自动找到并被测试。
*/
public void testEmptyCollection() {
System.out.println("in testEmptyCollection");
Collection collection = new ArrayList();
assertTrue(collection.isEmpty());
}
public void test1(){
System.out.println("in test1");
}
public void test2(){
System.out.println("in test2");
}
public void test3(){
System.out.println("in test3");
}
public static Test suite(){
//Constructs a TestSuite from the given class.
//Adds all the methods of the class starting with "test" as test cases to the suite.
return new TestSuite(SimpleTest.class);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
};
}
Junit 简单示例(使用TestSuite)
最新推荐文章于 2022-09-19 09:53:04 发布