2013-09-27 80 views
0

之前我使用build.xml(ant)來運行測試用例,但現在我使用pom.xml(maven)來運行測試用例。
當我有螞蟻時,我能夠得到testng-xslt報告,但在閱讀了許多博客和教程後,我無法通過pom生成。我想調查是什麼區別,我看到我的類路徑中有saxon.jar,但是它在pom.xml中缺少,因此我添加了依賴關係。第二件事,我注意到我沒有在pom.xml中指定.xml路徑(我不知道在pom中將它添加到哪裏)。 我在這裏同時提供了pom.xml和build.xml,請看看兩者,並讓我知道我錯過了什麼,以通過pom.xml生成testng-xslt報告,但它存在於build.xml中,我如何能解決該問題。
的build.xml「通過build.xml生成報告」和「通過pom.xml生成」有什麼區別?

<target name="testng-xslt-report"> 
      <delete dir="${basedir}/testng-xslt"> 
      </delete> 
      <mkdir dir="${basedir}/testng-xslt"> 
      </mkdir> 
      <xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"> 
       <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" /> 

       <param expression="true" name="testNgXslt.sortTestCaseLinks" /> 

       <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" /> 

       <param expression="true" name="testNgXslt.showRuntimeTotals" /> 

       <classpath location="D:\automation\windowsproject\zookeeper\lib\saxon-8.7.jar"> 
       </classpath> 
      </xslt> 
    </target> 

的pom.xml

<build> 
     <testResources> 
      <testResource> 
       <directory>src/test/resource</directory> 
       <excludes> 
        <exclude>**/*.java</exclude> 
       </excludes> 
      </testResource> 
     </testResources> 
     <plugins> 
      <plugin> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.12.4</version> 
       <configuration> 
        <suiteXmlFiles> 
         <suiteXmlFile> 
          C:/Users/windowspc/workspace/windows-project/Chrome.xml 
         </suiteXmlFile> 
        </suiteXmlFiles> 
        <testFailureIgnore> 
         true 
        </testFailureIgnore> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 

       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <reporting> 
     <plugins> 
      <plugin> 
       <groupId>org.testng.xslt</groupId> 
       <artifactId>testng-xslt-plugin</artifactId> 
       <version>1.1</version> 
       <configuration> 
        <outputDir>C:/Users/windowspc/workspace/windows-project/target/testng-xslt-report</outputDir> 
        <showRuntimeTotals>true</showRuntimeTotals> 
        <sortTestCaseLinks>true</sortTestCaseLinks> 
        <testDetailsFilter>FAIL,PASS,SKIP,CONF</testDetailsFilter> 
       </configuration> 
      </plugin> 
     </plugins> 
    </reporting> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>testng-xslt-plugin</id> 
      <url>http://uhftopic.com/maven/</url> 
     </pluginRepository> 
    </pluginRepositories> 
    ... 
    ... 
     <dependency> 
      <groupId>net.sourceforge.jexcelapi</groupId> 
      <artifactId>jxl</artifactId> 
      <version>2.6.12</version> 
     </dependency> 
     <dependency> 
      <groupId>net.sf.saxon</groupId> 
      <artifactId>saxon</artifactId> 
      <version>8.7</version> 
     </dependency> 

     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.5.2</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

回答

0

有這個插件的新版本。它的groupId/artifactId已更改。這裏是你可以用什麼:

<groupId>org.reportyng</groupId> 
<artifactId>reporty-ng</artifactId> 
<version>1.2</version> 

這裏是項目選址:https://github.com/cosminaru/reporty-ng/wiki/MavenPlugin

這裏是GitHub的庫:https://github.com/cosminaru/reporty-ng和插件庫現在的位置:

<pluginRepository> 
     <id>reporty-ng</id> 
     <url>https://github.com/cosminaru/reporty-ng/raw/master/dist/maven</url> 
    </pluginRepository> 

的主要區別螞蟻和maven之間是:

  • maven使用約定配置
  • 螞蟻需要被完全配置

這意味着,與螞蟻,你可以很容易地做任何你需要的,但你必須寫ant腳本來實現你所需要的。另一方面,maven對你的項目結構做了很多假設,如果你的項目結構符合這些假設:你可以做很多有用的工作,比如構建,測試,打包,生成幾乎沒有任何東西的文檔。 XML。

使用maven理解的一個重要的事情是life-cycle的概念。 Maven定義了3個生命週期:清潔生命週期,默認生命週期和現場生命週期。

  • 清潔:用它來清洗任何先前建立產品
  • 默認:用它來構建,測試,封裝項目
  • 網站:使用它來生成文件和報告

每生命週期是連續的階段。另外,每個階段都與一個插件目標綁定(一個插件目標與某個螞蟻目標類似)。生命週期的概念引入了插件執行之間的依賴關係(因此您不必指定它)。例如maven知道它在運行測試之前必須編譯源代碼和測試源代碼。

就你的情況而言:你需要生成一個報告,所以它可以在站點週期中完成。您需要根據測試結果生成報告,因此您需要在生成報告之前運行測試。要做到這一點,只需運行此Maven的命令:

mvn clean test site:site

此命令指示Maven來:

  • 清理任何以前的版本的產品(清潔生命週期)
  • 運行測試(默認生命週期)(maven知道它必須在運行測試之前編譯)
  • 使用文檔生成站點並且由於您定義了報告插件:它將在網站生成期間執行。

您可以在目標/站點目錄下找到您的報告。

另一件事要注意:撒克遜依賴是一個插件的依賴,而不是一個項目的依賴,所以你必須在<plugin>元素指定:

 <plugin> 
      <groupId>org.testng.xslt</groupId> 
      <artifactId>testng-xslt-plugin</artifactId> 
      <version>1.1</version> 
      <configuration> 
       <outputDir>C:/Users/windowspc/workspace/windows-project/target/testng-xslt-report</outputDir> 
       <showRuntimeTotals>true</showRuntimeTotals> 
       <sortTestCaseLinks>true</sortTestCaseLinks> 
       <testDetailsFilter>FAIL,PASS,SKIP,CONF</testDetailsFilter> 
      </configuration> 
      <dependencies> 
       <dependency> 
        <groupId>net.sf.saxon</groupId> 
        <artifactId>saxon</artifactId> 
        <version>8.7</version> 
       </dependency> 
      </dependencies> 
     </plugin>