如何运行带有故障安全的TestNG套件而无需解压缩依赖jar?

时间:2016-11-05 04:43:29

标签: java maven testng maven-surefire-plugin maven-failsafe-plugin

我想使用包含在依赖jar中的TestNG套件文件来执行集成测试。

details of setting up the pom.xml are discussed here

这是我目前拥有的pom文件。问题出在我需要定义套件文件的部分:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test</groupId>
  <artifactId>test-runner</artifactId>
  <version>1.0.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>${test.library.groupId}</groupId>
      <artifactId>${test.library.artifactId}</artifactId>
      <version>${test.library.version}</version>
    </dependency>
    <dependency>
      <groupId>${test.library.groupId}</groupId>
      <artifactId>${test.library.artifactId}</artifactId>
      <version>${test.library.version}</version>
      <classifier>tests</classifier>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.18</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>${test.suite}.xml</suiteXmlFile> <!-- <<< this is the issue -->
          </suiteXmlFiles>
          <dependenciesToScan>
            <dependency>${test.library.groupId}:${test.library.artifactId}</dependency>
          </dependenciesToScan>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

可以通过在Jenkins作业中提供参数值来执行测试:

    -Dtest.library.groupId=com.example.test
    -Dtest.library.artifactId=example
    -Dtest.library.version=2.0.1
    -Dtest.suite=smoke

如果套件文件在本地可用,这一切都可以正常工作,但是我想让套件文件只在jar中可用(与测试类相同)。没有拆包。

所以问题是:如何定义套件文件的位置(包含在依赖项中)?

这是有问题的部分:

<suiteXmlFile>[whatComesHere?]${test.suite}.xml</suiteXmlFile>

如何在测试jar中包含的套件文件中指出failsafe / surefire?或者这是不可能的,我只是为了能够运行特定的套件文件而解压缩jar?

1 个答案:

答案 0 :(得分:0)

使用surefire插件在配置部分中指定以下属性:

        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${version}</version>
        <configuration>
          <properties>
            <property>
              <name>testjar</name>
              <value>your.test.jar</value>
            </property>
            <property> <!--use if testng.xml is not in root directory-->
              <name>xmlpathinjar</name>
              <value>resources/testng.xml</value>
            </property>
          </properties>
        </configuration>