运行maven(3.5.2)构建Spring Boot 2.0.2.RELEASE应用程序(由Web初始化程序生成,具有Web依赖性)无法执行maven-surefire-plugin说:
错误:无法找到或加载主类org.apache.maven.surefire.booter.ForkedBooter
引起:java.lang.ClassNotFoundException:org.apache.maven.surefire.booter.ForkedBooter
为什么会这样?这是boot + surefire集成中的一个问题=一个bug?
作为参考,似乎相关的依赖关系是:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud) 我正在使用Jenkins,Maven 3.1和Java 1.6.我在Jenkins设置了以下Maven工作,具有以下目标和选项......
clean install -U -P cloudbees -P qa
Run Code Online (Sandbox Code Playgroud)
下面是我的pom.xml surefire配置...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx2048m -XX:MaxPermSize=512M </argLine>
<skipTests>false</skipTests>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,当我的单元测试失败时,Jenkins控制台输出仍然显示"BUILD SUCCESS"并且构建被标记为"不稳定"而不是完全失败.我如何配置Jenkins(或Maven,如果它是什么原样)的东西,以便我的构建失败(不会变得不稳定或通过),如果任何单元测试失败?
以下是控制台输出的内容
17:08:04 MyProjectOrganizationControllerTest.testRecoverFromError » IllegalState Failed to...
17:08:04 MyProjectOrganizationControllerTest.testVerifyDistrictListPopulated » IllegalState
17:08:04 MyProjectOrganizationControllerTest.testUpdateSchool » IllegalState Failed to loa...
17:08:04 MyProjectOrganizationControllerTest.testDeleteSchool » IllegalState Failed to loa...
17:08:04 MyProjectOrganizationControllerTest.testVerifyOrgListPopulatedPrivateSchoolOrgType » IllegalState
17:08:04 MyProjectOrganizationControllerTest.testSubmitMultipleParams » IllegalState Faile...
17:08:04
17:08:04 Tests run: 155, Failures: 0, Errors: 154, Skipped: 1
17:08:04
17:08:04 [ERROR] There are test failures.
17:08:04
17:08:04 …Run Code Online (Sandbox Code Playgroud) 我们为maven中的集成测试阶段生命周期定义了数百个测试,并且需要很长时间才能完成.
我想要做的只是运行一个测试integration-test.我试过做:
mvn -Dtest=<my-test> integration-test
Run Code Online (Sandbox Code Playgroud)
但这不起作用.将-Dtest只运行在单元测试目标测试,而不是集成测试阶段.我试过了-Dintegration-test=<my-test>,但是被忽略了.
有没有办法做到这一点 ?
我的配置是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/api/**</include>
</includes>
.....
Run Code Online (Sandbox Code Playgroud) NoSuchMethodErrorJUnit和Hamcrest组合的另一个例子.违规代码:
assertThat(dirReader.document(0).getFields(), hasItem(
new FeatureMatcher<IndexableField, String>(equalTo("Patisnummer"), "Field key", "Field key") {
@Override
protected String featureValueOf(IndexableField actual) {
return actual.name();
} } ));
Run Code Online (Sandbox Code Playgroud)
IndexerTest.java中的注释行152-157 (commit ac72ce)
导致NoSuchMethodError(请参阅http://db.tt/qkkkTE78以获取完整输出):
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.FeatureMatcher.matchesSafely(FeatureMatcher.java:43)
at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosingMatcher.java:55)
at org.hamcrest.core.IsCollectionContaining.matchesSafely(IsCollectionContaining.java:25)
at org.hamcrest.core.IsCollectionContaining.matchesSafely(IsCollectionContaining.java:14)
at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosingMatcher.java:55)
at org.junit.Assert.assertThat(Assert.java:770)
at org.junit.Assert.assertThat(Assert.java:736)
at indexer.IndexerTest.testIndexContainsField(IndexerTest.java:152)
Run Code Online (Sandbox Code Playgroud)
A NoSuchMethodError是由调用非现有方法的(已编译)类引起的.describeMismatchJUnit + Hamcrest组合的特定情况通常是由JUnit中包含的Hamcrest类与Hamcrest库中的那些类的版本之间的不兼容引起的.
聚甲醛包含Hamcrest库1.3,Hamcrest芯1.3,和JUnit 4.11的显式依赖,(按顺序)所建议加勒特厅在答复以获取:在运行测试时,"的NoSuchMethodError org.hamcrest.Matcher.describeMismatch" IntelliJ …
现在我有两种类型的测试但是当我说"mvn test"它只执行TestNG测试而不是Junit.我想一个接一个地执行.任何的想法 ?
我有src/test/java单元测试的默认文件夹.单独的文件夹src/integration/java可用于集成测试.
我将其配置为maven-surefire-plugin在各自的阶段执行单元/集成测试.当编译的类位于正确的目录中时,这非常有用.不幸的是,Maven只支持一个测试源文件夹和一个测试输出文件夹.
随着内行建立辅助插件,我可以添加其他的测试源文件夹,但已编译的类将生成到test-classes,但我想从编译类 src/integration/java成target/integration-test-classes.这可能吗?
src/test/java > target/test-classes
src/integration/java > target/integration-test-classes
Run Code Online (Sandbox Code Playgroud)
PS:我不喜欢这种排除/包含在基础解决方案上的解决方案(排除**/it/**默认测试阶段的所有文件,并将所有文件从**/unit/**集成阶段排除.
Maven的Surefire(测试)插件将mvn test-compile文件复制src/test/resources到target/test-classes.它编译.java的src/test/java,并复制编译的.class文件target/test-classes.
但它不会复制资源src/test/java,并且能够将测试资源放在.java与其资源类相同的目录中比在并行层次结构中更方便src/test/resources.
是否有可能让Maven从中复制资源src/test/java?
我读过Maven Failsafe插件是专门为运行集成测试而设计的.目前我正在开发一个多模块项目,集成测试在自己独立的模块中,用TestNg编写并使用Surefire插件运行.我们没有与单元测试冲突,因为只有集成测试在该模块的测试阶段运行.要在测试之前设置环境,并在运行测试后进行清理,@BeforeSuite @AfterSuite请使用TestNg注释.因此,不需要使用Failsafe插件使用的pre-integration-test阶段,integration-test阶段,post-integration-test阶段.
pre-integration-test,post-integration-test阶段无需编写Maven插件?testng integration-testing maven maven-surefire-plugin maven-failsafe-plugin
我正在使用以下SureFire配置构建Maven项目:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.maven-surefire-plugin}</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题是,当我构建它时mvn clean install -DskipTests=true,测试仍在执行中.可能是什么问题呢?
我尝试了两个-DskipTests(来自Maven网站)-DskipTests=true,当我选中"跳过测试"复选框时,它由IntelliJ Idea添加.
我不使用任何Maven settings.xml.
编辑 如果我注释掉SureFire插件配置,该参数的行为与我期望的一样.上面的配置可能有什么问题?
Maven Surefire插件有什么用?我找不到合适的例子.