2

我想使用包含在依賴關係jar中的TestNG套件文件來執行集成測試。如何在沒有解包依賴jar的情況下運行TestNG suite with failsafe?

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> 

的測試可以通過在詹金斯的工作參數提供值來執行:

-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文件?

回答

0

使用萬無一失插件指定以下在配置部分屬性:

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