你是否有喝咖啡等待JUnit结果的经历?

至少我有过,不仅仅是喝咖啡,甚至是吃中饭,睡午觉,等待JUnit运行结果,以前总是抱怨机器太慢,现在,似乎情况有些变化,看下面的一个例子,有2个测试案例类[1],每个类4个方法,每个方法休息5秒钟,那么做一个简单的算术题,需要多长时间?

2*4*5=40秒,完全正确,你可以去倒一杯水,然后回来看结果了!
我机器上JUnit的运行结果为:
Run as -> JUnit - 40268ms

会有其他不同结果吗?p-unit给你答案,下面这段代码是运行p-unit的main函数:
public static void main(String[] args) {
  SoloRunner runner = new SoloRunner();
  runner.setExecutorPool(new ExecutorPoolImpl(2));
  runner.run(LongTimeExecutionPUnitTestSuite.class);
}

答案是什么?
[solo] Started running samples.LongTimeExecutionPUnitTestSuite
TestSuite: samples.LongTimeExecutionPUnitTestSuite
samples.LongTimeExecutionTest1
samples.LongTimeExecutionTest2
test1() - [5021.0ms]
test1() - [5021.0ms]
test2() - [5003.0ms]
test2() - [5022.0ms]
testA() - [5020.0ms]
testA() - [5000.0ms]
testB() - [5001.0ms]
testB() - [5033.0ms]
total: 8, failures:0 (GREEN) - 20360.0ms

每个方法还是休息了5秒钟, 结果是20秒,不是40秒。

下载 p-unit-0.10 0.10 release
p-unit 主页: http://p-unit.sourceforge.net

[1] 测试案例类
LongTimeExecutionTest1.java/LongTimeExecution2.java:
public class LongTimeExecutionTest1(2) extends TestCase {
public void test1() throws Exception {
Thread.sleep(5000);
}

public void test2() throws Exception {
Thread.sleep(5000);
}

public void testA() throws Exception {
Thread.sleep(5000);
}

public void testB() throws Exception {
Thread.sleep(5000);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值