“通过build.xml生成报告”和“通过pom.xml生成”有什么区别?

时间:2013-09-27 08:56:03

标签: xslt ant testng pom.xml

之前我使用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

    <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>

1 个答案:

答案 0 :(得分: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>

ant和maven之间的主要区别是:

  • maven使用约定优于配置
  • ant需要完全配置

这意味着使用ant你可以轻松地做任何你需要的事情,但你必须编写ant脚本来实现你所需要的。另一方面,maven对您的项目结构做了很多假设,如果您的项目结构符合这些假设:您可以做很多有用的工作,比如构建,测试,打包,生成几乎没有任何内容的文档。 XML。

与maven理解的一个重要事项是life-cycle的概念。 maven定义了3个生命周期:清洁生命周期,默认生命周期和站点生命周期。

  • clean:用它来清理任何以前构建的产品
  • 默认:使用它来构建,测试,打包您的项目
  • site:用它来生成文档和报告

每个生命周期都是一系列阶段。另外,每个阶段都与插件目标绑定(插件目标在某种程度上类似于蚂蚁目标)。生命周期的概念引入了插件执行之间的依赖关系(因此您不必指定它)。例如,maven知道它必须在运行测试之前编译源代码和测试源。

在您的情况下:您需要生成一个报告,因此可以在site-lyfe-cycle期间完成。您需要根据测试结果生成报告,因此您需要在生成报告之前运行测试。要做到这一点,只需运行此maven命令:

mvn clean test site:site

此命令指示maven:

  • 清洁任何以前的构建产品(清洁生命周期)
  • 运行测试(默认生命周期)(maven知道它必须在运行测试之前编译)
  • 使用文档生成网站,因为您已经定义了报告插件:它将在网站生成期间执行。

您将在目标/网站目录下找到您的报告。

另外需要注意的是:saxon依赖项是插件的依赖项,而不是项目依赖项,因此您必须在<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>
相关问题