使用 jar 共享常见的 Spring Boot 集成测试?
Sharing common Springboot integration tests with jar?
我可以有一个包含 Springboot 集成测试的 jar 并在其他模块中使用这个 jar 来执行常见的集成测试吗?
如前所述here:
Maven projects already define a standard for a project's tests. And in
my opinion it doesn't make sense to make a project dependent on its
tests--if anything, tests would be dependent on the module under test,
since tests use the module, but not vice-versa.
尽管如果您仍然希望这样做,请回答您的问题:是的,这是可能的。 如所述 here:
There is a new way of running a test in Maven from another jar. from
maven-surefire-plugin version 2.15 you can tell Maven to scan your
test jars for tests and run them. You don't need to extract the tests
jar. Just add a dependency to your test jar like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<dependenciesToScan>
<dependency>test.jar.group:test.jar.artifact.id</dependency>
</dependenciesToScan>
</configuration>
</plugin>
我可以有一个包含 Springboot 集成测试的 jar 并在其他模块中使用这个 jar 来执行常见的集成测试吗?
如前所述here:
Maven projects already define a standard for a project's tests. And in my opinion it doesn't make sense to make a project dependent on its tests--if anything, tests would be dependent on the module under test, since tests use the module, but not vice-versa.
尽管如果您仍然希望这样做,请回答您的问题:是的,这是可能的。 如所述 here:
There is a new way of running a test in Maven from another jar. from maven-surefire-plugin version 2.15 you can tell Maven to scan your test jars for tests and run them. You don't need to extract the tests jar. Just add a dependency to your test jar like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<dependenciesToScan>
<dependency>test.jar.group:test.jar.artifact.id</dependency>
</dependenciesToScan>
</configuration>
</plugin>