如何创建一个带有测试的 jar 和 运行 它来自另一个版本的项目?
How to create a jar with tests and run it from another version of project?
我有一个版本为 1.0 的项目,包含 3 个包(maven 项目)。
项目 1(版本 1.0)
--------向后测试 (src/test/java + pom.xml)
------pack1 (src/main/java + pom.xml)
--------pack2 (src/main/java+ pom.xml)
我想保存带有此处测试的后向测试 jar,以便在版本 1.x 中使用,其中 x > 1。
版本为 1.x 的项目将显示如下:
项目 1(版本 1.1)
--------运行-测试 (pom.xml)
------pack1 (src/main/java + pom.xml)
--------pack2 (src/main/java+ pom.xml)
Thr 问题:后向测试和 运行-tests 包中的 pom.xml 文件应该如何让我 运行 进行测试?
我不得不提一下,向后测试依赖于 pack1 和 pack2。
谢谢你。
编辑:
我在 运行-tests pom.xml:
中尝试过类似的东西
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<dependenciesToScan>
<dependency>groupId:artifactId</dependency>
</dependenciesToScan>
</configuration>
</plugin>
但是没用。
Edit2:@andolsi zied 的答案可能很好,但是在 mvn clean install 上,即使我在我测试的 class 中添加了错误的更改,也没有失败的测试。
在向后测试中将此插件添加到 pom.xml maven 在向后测试中打包测试 class-test.jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
在运行-tests中添加这个依赖
<dependency>
<groupId>groupId</groupId>
<artifactId>backward-tests</artifactId>
<version>1.x</version>
<type>test-jar</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>groupId</groupId>
<artifactId>pack1</artifactId>
</exclusion>
<exclusion>
<groupId>groupId</groupId>
<artifactId>pack2</artifactId>
</exclusion>
</exclusions>
</dependency>
另一种 运行针对不同项目版本进行测试的方法是使用 git(或任何其他 SCM)。
- 在您的项目 V1 中创建一个 git 存储库
- 仅签入测试源
- 创建一个 git 分支
project-v1
并检查它。
- 签入项目生产代码V1
- 创建一个 git 分支
project-v2
并检查它。
- 签入项目生产代码V2
现在您可以 运行 在签出的版本(V1 或 V2)上进行测试。此外,您可以通过查看 SCM 的历史记录了解失败代码的确切区别。
我有一个版本为 1.0 的项目,包含 3 个包(maven 项目)。
项目 1(版本 1.0)
--------向后测试 (src/test/java + pom.xml)
------pack1 (src/main/java + pom.xml)
--------pack2 (src/main/java+ pom.xml)
我想保存带有此处测试的后向测试 jar,以便在版本 1.x 中使用,其中 x > 1。
版本为 1.x 的项目将显示如下:
项目 1(版本 1.1)
--------运行-测试 (pom.xml)
------pack1 (src/main/java + pom.xml)
--------pack2 (src/main/java+ pom.xml)
Thr 问题:后向测试和 运行-tests 包中的 pom.xml 文件应该如何让我 运行 进行测试?
我不得不提一下,向后测试依赖于 pack1 和 pack2。
谢谢你。
编辑:
我在 运行-tests pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<dependenciesToScan>
<dependency>groupId:artifactId</dependency>
</dependenciesToScan>
</configuration>
</plugin>
但是没用。
Edit2:@andolsi zied 的答案可能很好,但是在 mvn clean install 上,即使我在我测试的 class 中添加了错误的更改,也没有失败的测试。
在向后测试中将此插件添加到 pom.xml maven 在向后测试中打包测试 class-test.jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
在运行-tests中添加这个依赖
<dependency>
<groupId>groupId</groupId>
<artifactId>backward-tests</artifactId>
<version>1.x</version>
<type>test-jar</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>groupId</groupId>
<artifactId>pack1</artifactId>
</exclusion>
<exclusion>
<groupId>groupId</groupId>
<artifactId>pack2</artifactId>
</exclusion>
</exclusions>
</dependency>
另一种 运行针对不同项目版本进行测试的方法是使用 git(或任何其他 SCM)。
- 在您的项目 V1 中创建一个 git 存储库
- 仅签入测试源
- 创建一个 git 分支
project-v1
并检查它。 - 签入项目生产代码V1
- 创建一个 git 分支
project-v2
并检查它。 - 签入项目生产代码V2
现在您可以 运行 在签出的版本(V1 或 V2)上进行测试。此外,您可以通过查看 SCM 的历史记录了解失败代码的确切区别。