在Maven中,我試圖建立我的單元測試(使用maven-surefire-plugin
)自定義插件,但我收到以下錯誤:AssertionFailedError異常:Maven的3.2.4或更高要求(3.2.5運行版)
-------------------------------------------------------
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?爲什麼它沒有檢測到正確的版本?
任何幫助/建議將會非常有幫助。
P.S.在添加一個特定的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中心)。每次我更新版本時,錯誤都會改變(但在測試過程中仍然會發生)。現在我面臨着以下錯誤:
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
任何建議上依賴版本我應該改變?
它看起來像你的測試之一檢查的東西... – khmarbaise
我會看看那裏......'com.aaa.bbb.maven.plugin.eee.dddTest.setUp',第40行。 –
@FlorianSchaetz編輯刪除'setUp'後出現新錯誤的問題 –