qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          在Maven里使用TestNG的方法的單元測試實例

          要在Maven里面使用TestNG很簡單。去TestNG的網站上可以找到非常詳細的一段代碼,將下列代碼加入<dependencies></dependencies>標簽之間:
          <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <version>6.1.1</version>
          <scope>test</scope>
          </dependency>
            當然,這是對應的TestNG 6.1.1版本。其它版本的TestNG,應當只需要改動一下版本號即可。
            在src/main/java文件夾中書寫Main.java文件如下:
          package org.silentmusicbox.justanothermavenproject;
          public class Main {
          public String sayHello() {
          return "Hallo Welt!";
          }
          public static void main(String [] args) {
          Main objOfMain = new Main();
          System.out.println(objOfMain.sayHello());
          }
          }
            在src/test/java文件夾中書寫TestMain.java文件如下:
          packageorg.silentmusicbox.justanothermavenproject;
          importorg.testng.Assert;
          importorg.testng.annotations.BeforeMethod;
          importorg.testng.annotations.Test;
          publicclassTestMain{
          privateMainm;
          @BeforeMethod
          publicvoidinit(){
          m=newMain();
          }
          @Test
          publicvoidtestSayHello(){
          Assert.assertEquals(m.sayHello(),"HalloWelt!");
          }
          }
            運行mvn test,一切正常。如果將sayHello()方法中的返回值改為"Hello World!"則報錯。說明TestNG已經正常運行了。


          posted on 2013-12-26 11:06 順其自然EVO 閱讀(701) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年12月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 尼玛县| 白山市| 田林县| 崇礼县| 广丰县| 凤庆县| 五家渠市| 射洪县| 桂平市| 新密市| 毕节市| 乐东| 稷山县| 宣化县| 泰来县| 化隆| 库伦旗| 鄂伦春自治旗| 永川市| 佛山市| 东方市| 绍兴县| 花莲县| 蓝山县| 繁峙县| 桂阳县| 开化县| 壤塘县| 吴江市| 彭阳县| 修水县| 北海市| 泾川县| 伊川县| 塘沽区| 滦平县| 芮城县| 洮南市| 白银市| 阜新| 任丘市|