風人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
          數據加載中……

          多線程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);
          }

          posted on 2007-08-10 13:30 風人園 閱讀(663) 評論(0)  編輯  收藏 所屬分類: Test

          主站蜘蛛池模板: 囊谦县| 镇坪县| 阜南县| 芜湖市| 海原县| 嵊州市| 澳门| 岳阳市| 徐汇区| 桐城市| 青岛市| 汤阴县| 仁化县| 宾阳县| 子长县| 奇台县| 酒泉市| 丰台区| 临城县| 体育| 尉犁县| 陕西省| 兖州市| 宜阳县| 靖江市| 禄劝| 连州市| 霍林郭勒市| 家居| 班戈县| 洪泽县| 南雄市| 黄平县| 曲周县| 浮梁县| 阳春市| 云安县| 巫溪县| 富源县| 福贡县| 阿勒泰市|