Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有多模块项目的JUnit类别-无法加载类别_Java_Maven_Unit Testing_Testing_Junit4 - Fatal编程技术网

Java 具有多模块项目的JUnit类别-无法加载类别

Java 具有多模块项目的JUnit类别-无法加载类别,java,maven,unit-testing,testing,junit4,Java,Maven,Unit Testing,Testing,Junit4,我想包括/排除JUnit分类测试。我在一个通用模块中定义了一个标记接口StressTest。我在模块A中引用了StressTest。我在rootpom.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> <

我想包括/排除JUnit分类测试。我在一个通用模块中定义了一个标记接口
StressTest
。我在模块A中引用了
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>

我应该在哪里编写我的
StressTest
接口?

为了让surefire“找到”您的
@Category
类,它必须位于从Maven项目的依赖关系树生成的类路径上

这个例外

无法加载类别:com.mycompany.project.common.utils.StressTest

。。。强烈暗示任何包含
com.mycompany.project.common.utils.StressTest
的工件都不是
模块a
的声明依赖项

因此,您需要将对包含
com.mycompany.project.common.utils.StressTest
的任何工件的依赖项添加到您的
moduleA
。如果此依赖项的唯一目的是提供
@Category
类,则将此依赖项测试的范围限定为有意义的,例如

<dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>common.utils</artifactId>
    <version>...</version>
    <scope>test</scope>
</dependency>
然后,您可以使用
模块a
中的依赖项中的
测试jar
来依赖它,例如:

<dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>common.utils</artifactId>
    <version>...</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

com.mycompany
公用事业
...
试验罐
测试

如果我在test/java下定义了StressTest,那么它就不起作用了,但是如果我在main/java中定义了它,那么它就起作用了。@bluetech我已经更新了答案,以描述如何从您的通用utils模块导出并依赖一个
测试jar
  <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>
<dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>common.utils</artifactId>
    <version>...</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>