junit测试之并行测试
原创
©著作权归作者所有:来自51CTO博客作者mb5c80f4c73b73a的原创作品,请联系作者获取转载授权,否则将追究法律责任
在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());
}
}