我已经使用maven-archetype-plugin
原型生成了一个maven插件项目。
我将生成的集成测试src/it/simple-it/verify.groovy
更改为失败:
assert false
然后我调用:
$ mvn clean install invoker:integration-test invoker:verify
我的assert false
测试通过了:
[INFO] Installing /home/peter/ownCloud/Personal/eclipse-workspace/my-plugin/target/my-plugin-1.0-SNAPSHOT.jar to /home/peter/.m2/repository/org/example/my-plugin/1.0-SNAPSHOT/my-plugin-1.0-SNAPSHOT.jar
[INFO] Installing /home/peter/ownCloud/Personal/eclipse-workspace/my-plugin/pom.xml to /home/peter/.m2/repository/org/example/my-plugin/1.0-SNAPSHOT/my-plugin-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-invoker-plugin:3.1.0:integration-test (default-cli) @ my-plugin ---
[INFO] Building: simple-it/pom.xml
[INFO] simple-it/pom.xml ................................ SUCCESS (13.4 s)
[INFO]
[INFO] --- maven-invoker-plugin:3.1.0:verify (default-cli) @ my-plugin ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO] Passed: 1, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.975 s
[INFO] Finished at: 2019-03-03T08:23:34-04:00
[INFO] Final Memory: 38M/441M
[INFO] ------------------------------------------------------------------------
很明显,该测试实际上并未被调用。我想念什么?
为演示该问题,我创建了一个简单的shell脚本:
#!/bin/bash
rm -rf my-plugin
mvn archetype:generate -DgroupId=org.example -DartifactId=my-plugin -DarchetypeArtifactId=maven-archetype-plugin -DarchetypeVersion=1.4 -DinteractiveMode=false
cd my-plugin
echo assert false > src/it/simple-it/verify.groovy
mvn clean install invoker:integration-test invoker:verify
我相信,当达到invoker:verify目标时,该脚本应该在最后一行失败,并且maven执行verify.groovy
,实际上是assert false
。
答案 0 :(得分:0)
原型生成器正在为集成测试创建一个单独的概要文件,该概要文件默认情况下处于禁用状态。您需要运行以下命令来启用此配置文件:
mvn clean verify -Prun-its
然后您的测试将失败。
您可以通过添加以下内容来修改POM以默认启用此配置文件:
<activation>
<activeByDefault>true</activeByDefault>
</activation>
完整的配置文件块将是:
<profiles>
<profile>
<id>run-its</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<goals>
<goal>clean</goal>
<goal>test-compile</goal>
</goals>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
此时,您只需要运行:
mvn clean verify
,由于默认情况下现在运行IT测试,因此它也会失败。
有关Maven构建配置文件的更多信息,请查看Here。