我想要包含/排除JUnit分类测试。我在公共模块中定义了标记接口StressTest
。我在moduleA中引用了StressTest
。我在root pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<excludedGroups>com.mycompany.project.common.utils.StressTest</excludedGroups>
</configuration>
</plugin>
运行mvn测试时,我在构建另一个模块时会得到以下内容。
Unable to load category: com.mycompany.project.common.utils.StressTest
我应该在哪里写StressTest
界面?
答案 0 :(得分:2)
为了确保找到&#39;你的@Category
类必须在你的Maven项目的依赖树产生的类路径上。
此例外......
无法加载类别:com.mycompany.project.common.utils.StressTest
...强烈暗示包含com.mycompany.project.common.utils.StressTest
的任何工件不是moduleA
声明的依赖关系。
因此,您需要向com.mycompany.project.common.utils.StressTest
添加对包含moduleA
的任何工件的依赖关系。如果此依赖项的唯一目的是提供@Category
类,那么将此依赖项测试作为范围是有意义的。
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>common.utils</artifactId>
<version>...</version>
<scope>test</scope>
</dependency>
此外,如果com.mycompany.project.common.utils.StressTest
位于测试树中,而不是公共utils模块中的 main 树,那么您需要创建一个包含common utils模块的测试类。您可以通过将以下maven-jar-plugin
声明添加到常用工具来实现此目的。 pom.xml中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
然后,您在<type>test-jar</type>
的依赖关系中使用moduleA
依赖于此,例如:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>common.utils</artifactId>
<version>...</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>