【发布时间】:2013-11-27 16:19:00
【问题描述】:
我想定义项目范围的接口,用于@Category 注释,并配置 Maven 以在构建整个项目时排除它们的注释测试。
在 application 项目中有一个我想分类的测试:
@Category(Integration.class)
@Test
public void testExternalResource() { ... }
设置:
我已经建立了一个多模块的maven项目:
/container (has a pom with <modules> element)
/parent (all other modules inherit from its pom. has no source, only pom)
/util (other modules are depending on it)
/infra
/application (depending on infra and util, inherits from parent)
作为一个基础设施狂:),我想配置我的整个项目以排除任何模块中的组。所以,在我定义的 parent 模块中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<excludedGroups>com.mycompany.test.Integration</excludedGroups>
</configuration>
</plugin>
我已经将Integration 接口放在了util 模块中(在util/src/test/java 中),供所有模块查看:
package com.mycompany.test;
public interface Integration {}
因为它对于 util 和 application 都是 test-jar, I've made the right configuration。
错误:
在运行mvn clean install 时,我得到了
[ERROR] Failed to execute goal org.apache.maven.plugins:
maven-surefire-plugin:2.16:test
(default-test) on project util: Execution default-test of goal
org.apache.maven.plugins:maven-surefire-plugin:2.16:test
failed: There was an error in the forked process
[ERROR] java.lang.RuntimeException:
Unable to load category: com.mycompany.test.Integration
嗯,当然这个类是不可用的——我已经把它塞进了项目第一个模块的一个测试罐子里。 :(
我应该将我的Integration 接口放在哪里,以便我的 mvn 配置和源代码可以使用它?
【问题讨论】:
标签: maven junit integration-testing maven-surefire-plugin