Read Sean

          Read me, read Sean.
          posts - 508, comments - 655, trackbacks - 9, articles - 4

          [Eclipse筆記](méi)Give TestNG a try in Eclipse

          Posted on 2005-04-13 22:10 laogao 閱讀(1200) 評(píng)論(3)  編輯  收藏 所屬分類: On JavaOn Eclipse


          自從接觸J2SE 5.0以來(lái),似乎Cedric Beust這個(gè)名字就在腦海中揮之不去,大約是跟他在java.sun.com的一篇對(duì)J2SE 5.0新特性的介紹文章有關(guān)吧,其實(shí)這個(gè)法國(guó)人給人留下印象最深的是他基于JUnit和J2SE 5.0的注解(Annotation)的思想創(chuàng)作的測(cè)試工具:TestNG。

          用過(guò)JUnit的朋友,尤其是經(jīng)常使用的朋友大概會(huì)跟他有同感,那就是JUnit有些時(shí)候功能顯得太單調(diào),不夠靈活,但是很少有人像他那樣自己另起爐灶去寫一個(gè)自己的測(cè)試框架。也許這就是我們跟發(fā)達(dá)國(guó)家在技術(shù)創(chuàng)新上的差距吧,我想這至少是意識(shí)上的差距。

          國(guó)外各大網(wǎng)站已經(jīng)前前后后做了不少介紹,國(guó)內(nèi)網(wǎng)站則似乎還沒(méi)有十分重視這個(gè)看上去不起眼的家伙。這究竟是個(gè)什么樣的工具呢?有些什么特色?大致總結(jié)一下就是:

          對(duì)Java注解的支持
          利用XML配置測(cè)試過(guò)程
          不需要實(shí)現(xiàn)接口或繼承類(如JUnit的TestCase/TestSuite)
          支持獨(dú)立的方法和分組
          支持并行測(cè)試
          測(cè)試方法支持傳入?yún)?shù)
          任意制定的調(diào)用次數(shù)和成功率統(tǒng)計(jì)

          現(xiàn)在,我們有機(jī)會(huì)在Eclipse環(huán)境嘗試這個(gè)測(cè)試框架了,還要多多感謝TestNG插件的作者Alexandru Popescu犧牲掉那么多自己的時(shí)間。怎么樣?躍躍欲試?該插件的update site是:http://beust.com/eclipse/,需要注意的是它目前只支持Eclipse 3.1版本,因?yàn)镴ava注解的原因。

          為了簡(jiǎn)單做一個(gè)演示,我隨便寫了一些代碼:

          [FooCalculator.java]

          package sean.home.test;

          public class FooCalculator {
              
              
          public static int increaseByOne(int origVal) {
                  
          return ++origVal;
              }


          }


          [FooCalculatorTest.java]

          package sean.home.test;

          import com.beust.testng.annotations.
          *;

          public class FooCalculatorTest {
              
              
          private int origVal;
              
              @Configuration (beforeTestClass 
          = true)
              
          public void setUp() {
                  origVal 
          = Integer.MAX_VALUE;
              }

              
              @Test
              
          public void testIncreasByOne() {
                  
          int result = FooCalculator.increaseByOne(origVal);
                  assert result 
          > 0;
              }

              
          }


          [TestFooCalculator.xml]

          <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >

          <suite name="Custom Suite" >
              
          <test name="To Test FooCalculator" >
                  
          <classes>
                      
          <class name="sean.home.test.FooCalculatorTest" />
                  
          </classes>
              
          </test>
          </suite>


          完成以后,我們可以在Eclipse中右鍵選中我們的測(cè)試類或者配置文件,選運(yùn)行TestNG,這樣我們就能看到Console視圖和TestNG視圖中顯示的結(jié)果了。

          更多信息,參考:http://beust.com/testng/

          Feedback

          # re: [Eclipse筆記](méi)Give TestNG a try in Eclipse  回復(fù)  更多評(píng)論   

          2005-05-17 16:15 by Kukoo
          How do u convert the Java/XML source code to such a nice HTML? (even support to folder the source code)

          # re: [Eclipse筆記](méi)Give TestNG a try in Eclipse  回復(fù)  更多評(píng)論   

          2005-05-19 19:17 by Kukoo
          hehe, knew how to do it already.

          # re: [Eclipse筆記](méi)Give TestNG a try in Eclipse  回復(fù)  更多評(píng)論   

          2005-05-22 20:52 by 大胃
          :)
          主站蜘蛛池模板: 财经| 夏河县| 古交市| 泰州市| 清水河县| 黄浦区| 新民市| 湘乡市| 潼关县| 秦皇岛市| 个旧市| 丹东市| 益阳市| 荔波县| 大名县| 宝清县| 天镇县| 大宁县| 芜湖县| 固安县| 大名县| 陵水| 宣威市| 靖西县| 宿迁市| 吉木萨尔县| 敦化市| 台北市| 福泉市| 苍南县| 曲麻莱县| 井研县| 安国市| 泰宁县| 天水市| 辽阳县| 金坛市| 郧西县| 修文县| 石柱| 涞源县|