多線程UT(p-unit)(zt)
至少我有過,不僅僅是喝咖啡,甚至是吃中飯,睡午覺,等待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);
}
}
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);
}
}
posted on 2007-08-10 13:30 風人園 閱讀(663) 評論(0) 編輯 收藏 所屬分類: Test