在junit中,还可以同时执行多个单元测试,例子如下:
然后用一个数组存放
import junit.framework.Assert;
import org.junit.Test;
public class TestFeatureOne {
@Test
public void testFirstFeature()
{
Assert.assertTrue(true);
}
}
public class TestFeatureTwo {
@Test
public void testSecondFeature()
{
Assert.assertTrue(true);
}
}
然后用一个数组存放
public class WithJUnitCore
{
public static void main(String[] args)
{
List testCases = new ArrayList();
//Add test cases
testCases.add(TestFeatureOne.class);
testCases.add(TestFeatureTwo.class);
for (Class testCase : testCases)
{
runTestCase(testCase);
}
}
private static void runTestCase(Class testCase)
{
Result result = JUnitCore.runClasses(testCase);
for (Failure failure : result.getFailures())
{
System.out.println(failure.toString());
}
}
本文介绍如何使用JUnit框架同时执行多个单元测试案例。通过创建测试类并利用JUnitCore运行器来实现这一目标,确保所有测试案例都能被有效地执行。
311

被折叠的 条评论
为什么被折叠?



