【发布时间】:2023-03-21 04:48:01
【问题描述】:
在 Maven 中,我正在尝试使用单元测试(使用 maven-surefire-plugin)构建我的自定义插件,但我收到以下错误:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.aaa.bbb.maven.plugin.eee.dddTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.038 sec <<< FAILURE!
testSomething(com.aaa.bbb.maven.plugin.eee.dddTest) Time elapsed: 0.009 sec <<< FAILURE!
junit.framework.AssertionFailedError: Maven 3.2.4 or better is required
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:149)
at com.aaa.bbb.maven.plugin.eee.dddTest.setUp(dddTest.java:40)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:95)
at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:121)
at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Results :
Failed tests: testSomething(com.aaa.bbb.maven.plugin.eee.dddTest): Maven 3.2.4 or better is required
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.950 s
重要的一行是:
junit.framework.AssertionFailedError: Maven 3.2.4 or better is required
但是当我检查版本时,我看到:
$ mvn -version
Apache Maven 3.2.5
如果我使用-DskipTests 跳过测试,它构建得很好。为什么会发生此错误?也许我正在使用一些需要 Maven 3.2.5 的依赖项?为什么它没有检测到正确的版本?
任何帮助/建议都会非常有帮助。
附:在我添加了一个特定的 mojo 之后,这个错误就开始发生了。如果我删除 Mojo,它会构建得很好。 Mojo 中的什么可能导致它?
编辑:
我从dddTest.java 中删除了Setup(),但我仍然收到同样的错误,只是没有指定行。新错误:
junit.framework.AssertionFailedError: Maven 3.2.4 or better is required
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:149)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:95)
at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:121)
at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
有什么想法吗?
编辑 2:
我看到了here 的问题,我意识到依赖版本存在一些问题。所以我更新了链接上提到的 maven 依赖项的版本,然后更新了一些版本(基于将依赖关系树与 maven Central 进行比较)。每次我更新版本时,错误都会发生变化(但在测试期间仍然会发生)。现在我面临以下错误:
java.lang.NoSuchMethodError: org.codehaus.plexus.ContainerConfiguration.setClassPathScanning(Ljava/lang/String;)Lorg/codehaus/plexus/ContainerConfiguration;
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainerConfiguration(AbstractMojoTestCase.java:285)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainer(AbstractMojoTestCase.java:259)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.getContainer(AbstractMojoTestCase.java:298)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:152)
at com.aaa.bbb.maven.plugin.eee.dddTest.setUp(dddTest.java:39)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
此错误的依赖关系树:
+- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.5:provided
+- org.apache.maven.plugin-testing:maven-plugin-testing-harness:jar:3.3.0:test
| +- commons-io:commons-io:jar:2.2:compile
| \- org.codehaus.plexus:plexus-archiver:jar:2.2:test
| \- org.codehaus.plexus:plexus-io:jar:2.0.4:test
+- org.apache.maven:maven-artifact:jar:3.3.9:compile
| +- org.codehaus.plexus:plexus-utils:jar:3.0.22:compile
| \- org.apache.commons:commons-lang3:jar:3.4:compile
+- org.apache.maven.shared:maven-filtering:jar:3.1.1:compile
| +- org.codehaus.plexus:plexus-interpolation:jar:1.22:compile
| \- org.sonatype.plexus:plexus-build-api:jar:0.0.7:compile
+- org.yaml:snakeyaml:jar:1.17:compile
+- org.apache.commons:commons-compress:jar:1.14:compile
+- org.apache.maven.shared:maven-invoker:jar:3.0.0:compile
| \- org.codehaus.plexus:plexus-component-annotations:jar:1.7:compile
+- org.apache.maven:maven-core:jar:3.3.9:compile
| +- org.apache.maven:maven-model:jar:3.3.9:compile
| +- org.apache.maven:maven-settings:jar:3.3.9:compile
| +- org.apache.maven:maven-settings-builder:jar:3.3.9:compile
| | \- org.apache.maven:maven-builder-support:jar:3.3.9:compile
| +- org.apache.maven:maven-repository-metadata:jar:3.3.9:compile
| +- org.apache.maven:maven-plugin-api:jar:3.3.9:provided
| +- org.apache.maven:maven-model-builder:jar:3.3.9:compile
| | \- com.google.guava:guava:jar:18.0:compile
| +- org.apache.maven:maven-aether-provider:jar:3.3.9:compile
| | \- org.eclipse.aether:aether-spi:jar:1.0.2.v20150114:compile
| +- org.eclipse.aether:aether-impl:jar:1.0.2.v20150114:compile
| +- org.eclipse.aether:aether-api:jar:1.0.2.v20150114:compile
| +- org.eclipse.aether:aether-util:jar:1.0.2.v20150114:compile
| +- com.google.inject:guice:jar:no_aop:4.0:compile
| | +- javax.inject:javax.inject:jar:1:compile
| | \- aopalliance:aopalliance:jar:1.0:compile
| +- org.codehaus.plexus:plexus-classworlds:jar:2.5.2:compile
| \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
| \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
+- org.apache.maven:maven-plugin-descriptor:jar:2.2.1:compile
+- org.apache.maven.reporting:maven-reporting-exec:jar:1.3:compile
| +- org.apache.maven.reporting:maven-reporting-api:jar:3.0:compile
| | \- org.apache.maven.doxia:doxia-sink-api:jar:1.0:compile
| \- org.sonatype.aether:aether-util:jar:1.7:compile
+- org.apache.maven.shared:maven-shared-utils:jar:3.1.0:compile
+- org.codehaus.plexus:plexus-container-default:jar:1.7.1:compile
| +- org.apache.xbean:xbean-reflect:jar:3.7:compile
| \- com.google.collections:google-collections:jar:1.0:compile
+- junit:junit:jar:4.12:compile
| \- org.hamcrest:hamcrest-core:jar:1.3:compile
\- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.3:compile
+- javax.enterprise:cdi-api:jar:1.0:compile
| \- javax.annotation:jsr250-api:jar:1.0:compile
\- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.3:compile
关于我应该更改哪个依赖版本的任何建议?
【问题讨论】:
-
看起来您的一项测试正在检查某些内容...
-
我会去那里看看...
com.aaa.bbb.maven.plugin.eee.dddTest.setUp,第 40 行。 -
@FlorianSchaetz 在删除
setUp后编辑了带有新错误的问题 -
@khmarbaise 在删除
setUp后编辑了带有新错误的问题
标签: java maven junit maven-plugin maven-surefire-plugin