我想定义项目范围的接口,以在@Category
批注中使用,并配置Maven以在构建整个项目时排除其批注的测试。
在应用程序项目中,有一个我要分类的测试:
@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)
作为基础设施上的怪胎:),我想将我的整个项目配置为排除任何模块中的组。因此,在父模块中,我定义了:
<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 {}
而且因为它是a test-jar
,所以我已经为util和application进行了正确的配置。
跑步时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模块,并将接口放在下src/main/java/
。确保junit
可用作编译时依赖项(<scope>compile</scope>
)-基本上是在构建其他测试可以使用的依赖项。因此src/test/java
,像往常一样,将有助于其他测试的代码放到main中,而将其用于的测试则放在。
这一步感觉有点奇怪,但是请考虑如何打包junit
自身。从的角度来看junit
,它只是一个普通的Java库,因此所有代码都放入了main
。
当您需要此模块时,可将其用作测试依赖项 <scope>test</scope>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句