如何运行带有故障安全的TestNG套件而无需解压缩依赖jar? [英] How to run TestNG suite with failsafe without unpacking dependency jar?

查看:168
本文介绍了如何运行带有故障安全的TestNG套件而无需解压缩依赖jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to execute integration tests using a TestNG suite file which is contained in a dependency jar.

这里讨论了设置pom.xml的详细信息

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

Here's the pom file I currently have. The problem is with the part where I need to define a suite file:

<?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作业中提供参数值来执行测试:

The tests can be executed by providing values for the parameters in the Jenkins job:

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

一切正常如果套件文件在本地可用,但我想使它只能在jar中使用套件文件(与测试类相同)。没有解包。

This all works fine if the suite file is available locally, but I'd like to make it work with the suite file only being available in the jar (same as the test classes). No unpackaging.

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

So the question is: How do I define the location of the suite file (which is packaged in the dependencies)?

这是有问题的部分:

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

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

How can I point failsafe / surefire at a suite file that is contained in the test jar? Or is this not possible and I would have to unpack the jar just for the sake of being able to run a specific suite file?

推荐答案

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

Using surefire plugin specify following properties in configuration section:

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

这篇关于如何运行带有故障安全的TestNG套件而无需解压缩依赖jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆