在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());
}
}