Sky's blog

          我和我追逐的夢(mèng)

          常用鏈接

          統(tǒng)計(jì)

          其他鏈接

          友情鏈接

          最新評(píng)論

          TestNG官方文檔中文版(5)-測(cè)試方法/類和組

          5 - Test methods, Test classes and Test groups
          5.1 - Test groups

          TestNG容許執(zhí)行復(fù)雜的測(cè)試方法分組。不僅可以申明方法屬于組,而且可以指定分組包含其他分組。
          然后TestNG可以被調(diào)用,并被要求包含某些分組和排除其他的分組。
          這將提供怎樣劃分測(cè)試的最大彈性,并且如果想運(yùn)行兩個(gè)不同的測(cè)試裝置不需要重新編譯。

          例如,非常普遍的需要至少兩個(gè)種類的測(cè)試

              * Check-in tests.  這些測(cè)試將在提交新代碼之前運(yùn)行. 它們典型的被要求快速而且僅僅確認(rèn)沒有基礎(chǔ)功能被破壞。
              * Functional tests.  這些測(cè)試將覆蓋所有的軟件功能,并且必須運(yùn)行至少1天,盡管理想的是連續(xù)運(yùn)行.

          代表性的,check-in測(cè)試是功能性測(cè)試的子集。TestNG容許用非常直接的方式說明這個(gè)。
          例如: 可以這樣構(gòu)造測(cè)試,申明完整的測(cè)試類屬于"functest"組,另外兩個(gè)方法屬于組"checkintest":

          public class Test1 {
            @Test(groups = { "functest", "checkintest" })
            public void testMethod1() {
            }

            @Test(groups = {"functest", "checkintest"} )
            public void testMethod2() {
            }

            @Test(groups = { "functest" })
            public void testMethod3() {
            }

          }

          調(diào)用TestNG,使用

          <test name="Test1">
            <groups>
              <run>
                <include name="functest"/>
              </run>
            </groups>
            <classes>
              <class name="example1.Test1"/>
            </classes>
          </test>
          將運(yùn)行在類中的所有測(cè)試方法,如果使用checkintest調(diào)用則將只運(yùn)行testMethod1()和testMethod2().

          這里由其他例子,這次使用正則表達(dá)式。假設(shè)某些測(cè)試方法可能無(wú)法在Linux上運(yùn)行,測(cè)試將是類似如此:
          @Test
          public class Test1 {
            @Test(groups = { "windows.checkintest" })
            public void testWindowsOnly() {
            }

            @Test(groups = {"linux.checkintest"} )
            public void testLinuxOnly() {
            }

            @Test(groups = { "windows.functest" )
            public void testWindowsToo() {
            }
          }

          你可以使用下面的testng.xml文件只啟動(dòng)Windows方法:

          <test name="Test1">
            <groups>
              <run>
                <include name="windows.*"/>
              </run>
            </groups>

            <classes>
              <class name="example1.Test1"/>
            </classes>
          </test>

          注意:TestNG使用正則表達(dá),而不是wildmats。注意這個(gè)差別。

          Method groups
          同樣可以包含或排除個(gè)別方法:

          <test name="Test1">
            <classes>
              <class name="example1.Test1">
                <methods>
                  <include name=".*enabledTestMethod.*"/>
                  <exclude name=".*brokenTestMethod.*"/>
                </methods>
               </class>
            </classes>
          </test>

          這在需要使莫個(gè)單獨(dú)的方法失效而不想重新編譯時(shí)非常方便,但是不建議太多的使用這個(gè)機(jī)制,因?yàn)檫@將可能破壞你的測(cè)試框架 如果你開始重構(gòu)你的java代碼(標(biāo)簽中使用的正則表達(dá)式可能不再匹配你的方法)
          5.2 - Groups of groups

          "functest" itself will contain the groups "windows" and "linux" while "checkintest will only contain "windows".  Here is how you would define this in your property file:
          組可以包含其他組。這些組被稱為"MetaGroups"。例如,你可能想定義一個(gè)"all"組,包括"checkintest"和"functest"。"functest"自身將包含組 "windows" 和 "linux",而"checkintest"將包含"windows".

          <test name="Regression1">
            <groups>
              <define name="functest">
                <include name="windows"/>
                <include name="linux"/>
              </define>
           
              <define name="all">
                <include name="functest"/>
                <include name="checkintest"/>
              </define>
           
              <run>
                <include name="all"/>
              </run>
            </groups>
           
            <classes>
              <class name="test.sample.Test1"/>
            </classes>
          </test>

          5.3 - Exclusion groups

          TestNG 容許包含組也容許排除組.

          例如,當(dāng)由因?yàn)樽罱男薷亩R時(shí)破壞的測(cè)試而又沒有時(shí)間去修復(fù)它們時(shí)非常有用。無(wú)論如何,你想要干凈的運(yùn)行功能性測(cè)試,因此你想要是這些測(cè)試失效,但是記住它們重新被激活。
          一個(gè)簡(jiǎn)單的解決這個(gè)問題的方法是創(chuàng)建一個(gè)稱為"broken"的組并讓這些測(cè)試方法歸屬它。例如,在上面的例子中,我知道testMethod2() 現(xiàn)在被破壞了,所有我想關(guān)閉它:

          @Test(groups = {"checkintest", "broken"} )
          public void testMethod2() {
          }

          現(xiàn)在我所想要做的只是在運(yùn)行中排除這個(gè)組:

          <test name="Simple example">
            <groups>
              <run>
                <include name="checkintest"/>
                <exclude name="broken"/>
              </run>
            </groups>
           
            <classes>
              <class name="example1.Test1"/>
            </classes>
          </test>

          用這種方法,我將得到一個(gè)干凈的測(cè)試運(yùn)行,同時(shí)記錄了那些被破壞并想要后續(xù)修復(fù)的測(cè)試。
          注意:你也可以通過使用在@Test and @Before/After annotations上的"enabled"屬性在個(gè)體的層面上關(guān)閉測(cè)試,

          5.4 - Partial groups
          你可以在類的級(jí)別上定義組,然后在方法的層次上添加組:

          @Test(groups = { "checkin-test" })
          public class All {

            @Test(groups = { "func-test" )
            public void method1() { ... }

            public void method2() { ... }
          }

          在這個(gè)類中,method2() 屬于組"checkin-test",在類的級(jí)別定義。而method1() 同時(shí)屬于 "checkin-test" 和 "func-test".

          posted on 2008-03-23 13:14 sky ao 閱讀(2253) 評(píng)論(5)  編輯  收藏 所屬分類: software test

          評(píng)論

          # re: TestNG官方文檔中文版(5)-測(cè)試方法/類和組 2008-03-23 13:25 完美世界私服

          http://www.wmsifu.cn  回復(fù)  更多評(píng)論   

          # re: TestNG官方文檔中文版(5)-測(cè)試方法/類和組 2008-03-23 13:30 飄然

          暈倒,私服廣告做到這里來(lái)了...

          大家不要點(diǎn),無(wú)視一樓。  回復(fù)  更多評(píng)論   

          # re: TestNG官方文檔中文版(5)-測(cè)試方法/類和組 2008-03-24 11:39 阿里

          謝謝!
          希望樓主翻譯完后做個(gè)目錄。  回復(fù)  更多評(píng)論   

          # re: TestNG官方文檔中文版(5)-測(cè)試方法/類和組 2008-03-24 21:03 mei

          如何把一個(gè)excel文件中內(nèi)容或者.csv file中內(nèi)容讀出,這個(gè)是不是叫做data dirive?   回復(fù)  更多評(píng)論   

          # re: TestNG官方文檔中文版(5)-測(cè)試方法/類和組 2008-12-07 00:14 阿虎

          謝謝lz
          交個(gè)朋友吧  回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 阳山县| 辉县市| 穆棱市| 玛沁县| 灵台县| 托克逊县| 德化县| 洛南县| 黄山市| 阜城县| 义马市| 大兴区| 襄樊市| 深圳市| 遂宁市| 宜州市| 南雄市| 重庆市| 镇雄县| 鹤峰县| 宽甸| 尼玛县| 平昌县| 丰都县| 随州市| 大同县| 中牟县| 吕梁市| 清镇市| 株洲县| 江口县| 木兰县| 米林县| 阜新市| 德格县| 中卫市| 莲花县| 永州市| 萨迦县| 民勤县| 巴林右旗|