【发布时间】:2015-12-19 18:03:29
【问题描述】:
我正在尝试在命令行上使用 TestNG,以便针对本地开发服务器执行一套集成测试,其中 test-jar-with-dependencies.jar 包含要执行的集成测试。
但是,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 套件中定义的测试将被执行,但没有一个被执行。
【问题讨论】:
标签: java maven testng integration-testing maven-assembly-plugin