簡體   English   中英

如何執行側面測試罐中包含的一組TestNG集成測試?

[英]How do I execute a suite of TestNG integration tests contained in a side test-jar?

我試圖在命令行上使用TestNG以便對本地開發服務器執行一套集成測試,其中test-jar-with-dependencies.jar包含要執行的集成測試。

但是,似乎沒有執行src/integration-test/中的src/integration-test/

$ java -classpath ".;testng-6.8.8.jar;jcommander-1.27.jar;coolthing.diagnostic-5.0-SNAPSHOT-test-jar-with-dependencies.jar" org.testng.TestNG testng.xml

=========================================
diagnostic-suite
Total tests run: 0, Failures: 0, Skips: 0
=========================================

由於maven-jar-plugin似乎沒有打包測試依賴項,因此我選擇使用maven-assembly-plugin組裝測試jar,其中,組裝描述符的定義如下:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>test-jar-with-dependencies</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <useProjectAttachments>true</useProjectAttachments>
            <unpack>true</unpack>
            <scope>test</scope>
        </dependencySet>
    </dependencySets>
</assembly>

為了在Maven安裝階段中進行組裝,我附加了組裝描述符,如下所示:

<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>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/integration-test/resources/test-jar-with-dependencies.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

這部分似乎工作正常,但我無法執行測試JAR中包含的集成測試。 TestNG套件XML文件的定義如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="diagnostic-suite" parallel="classes" thread-count="4">
    <test name="endpoints">
        <groups>
            <dependencies>
                 <group depends-on="ping" name="diagnostic"></group>
            </dependencies>
            <run>
                <include name="ping" />
                <include name="diagnostic" />
            </run>
        </groups>

        <classes>
            <class name="our.company.ping.CoolThingPingIT" />
            <class name="our.company.status.CoolThingIndexIT" />
            <class name="our.company.status.CoolThingConfigurationIT" />
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

您能想到我可能錯過的地方嗎? 預期的結果是將執行TestNG套件中定義的測試,但是不會執行任何測試。

嘗試使用testjar和xmlpath選項。

java -cp MyProject-jar-with-dependencies.jar; MyProject.jar; MyProject-tests.jar org.testng.TestNG -testjar MyProject-tests.jar -xmlpathinjar suites/GroupBased_Tests.xml

我在這里記錄了類似的要求

就包裝測試罐而言,這是我所擁有的:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-tests</id>
            <phase>package</phase>
            <goals>
                <!-- Always build a test-jar (if test classes present) -->
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

在從jar運行測試方面, 請查看此問題以及我在此處發布的內容

我已經標記了與您相關的部分(“ dependencies”部分,然后是“ dependenciesToScan”部分):

<?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> <!-- <<< dependencies, incl. the "tests" dependency -->
    <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> <!-- <<< this is what makes you find the tests within the jar -->
            <dependency>${test.library.groupId}:${test.library.artifactId}</dependency>
          </dependenciesToScan>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM