为了清理一个巨大的烂摊子的事,我开始把我的测试代码都在一个普通的Java项目(所有的src/main/JAVA),然后声明,作为一个<scope>test</scope>在另一个项目的依赖,并期待要运行的测试.
没有这样的运气.surefire想要运行它可以在源代码中看到的测试.
我可以看到一个可悲的是显而易见的解决方案在这里涉及构建辅助性插件,并添加测试到测试编译环境为源目录,但我希望避免它.
如果你想知道,这一切的原因是,使用故障安全插件的运行一些集成测试的POM的配置有这么复杂,我想从测试的运行打出了测试类的编译.
现在可以使用Maven Surefire v2.15.只需将以下类型的配置添加到surefire插件:
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<dependenciesToScan>
<dependency>com.group.id:my-artifact</dependency>
<dependency>com.group.id:my-other-artifact</dependency>
</dependenciesToScan>
...
</configuration>
...
</plugin>
...
</build>
Run Code Online (Sandbox Code Playgroud)
您还应该在依赖项部分中声明实际的依赖项:
<dependencies>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>my-artifact</artifactId>
<type>test-jar</type>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.group.id</groupId>
<artifactId>my-other-artifact</artifactId>
<type>test-jar</type>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4156 次 |
| 最近记录: |