Maven验证程序集成测试未找到测试中的工件

时间:2016-03-05 18:07:35

标签: java maven integration-testing

我有一个maven项目(github),它广泛使用Maven集成测试verifier

测试是指我正在测试的项目。例如,pom执行此操作:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>1.4.1</version>
      <dependencies>
        <dependency>
          <!-- My project which customizes the plugin. -->
          <groupId>com.google.security</groupId>
          <artifactId>fences-maven-enforcer-rule</artifactId>
          <version>1.2-beta-SNAPSHOT</version>
        </dependency>
      </dependencies>
      ...

该依赖关系是相对路径../../../../../ pom.xml。

然后我的junit test使用Verifier来运行集成测试。

// testProjectName is the basename of the directory
// containing the POM above.

File testDir = ResourceExtractor.simpleExtractResources(
    getClass(), "/" + testProjectName);

Verifier verifier = new Verifier(
    testDir.getAbsolutePath(),
    null, debug == Debug.VERBOSE, true /* forkJvm */);
// Clean up after previous runs.
verifier.deleteArtifacts("test");
Result goalResult = Result.PASS;
try {
  verifier.executeGoal("verify");
} catch (@SuppressWarnings("unused") VerificationException ex) {
  goalResult = Result.FAIL;
}

我可以通过执行mvn install -DskipTests=true && mvn test来测试这个,但这不太理想,因为如果我在没有重新安装的情况下更改代码,我最终会针对过时版本运行测试,并且因为有人下载了项目这是第一次不能只做mvn test

是否有某种方法可以调整POM或junit TestCase,以便依赖于刚刚编译为target/classes的类?

1 个答案:

答案 0 :(得分:1)

在构建dependend项目之前,您需要构建和安装depenendy,或者两者都必须是同一个reactor构建的一部分。我认为如果它在同一个模块中是不起作用的(至少没有工件依赖,测试类自动在测试类路径上 - 但插件可能不会从那里加载)。