2016-08-08 55 views
0

我有這個問題已有3天了,我不知道如何解決它... 這裏是: 我正在使用Cucumber和Maven進行驗收測試。CucumberException未能instanciate類

我所有的測試都很好,我創建了一個jar庫,作爲我想要測試的項目的pom.xml文件中的依賴項導入。

一切工作順利,直到我只是改變了我的罐子我進口組ID的名稱...

然而,我爲我的項目,我想導入以JAR庫「MVN安裝」命令再次運行我的項目來測試(顯然我改變了我的pom.xml文件中的依賴)。

現在我得到的錯誤是:

cucumber.runtime.CucumberException: Failed to instantiate class cucumber.steps.myClass 
     at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:46) 
     at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:32) 
     at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38) 
     at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37) 
     at cucumber.runtime.Runtime.runStep(Runtime.java:299) 
     at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44) 
     at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39) 
     at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44) 
     at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91) 
     at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63) 
     at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18) 
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
     at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
     at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70) 
     at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93) 
     at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37) 
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
     at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
     at cucumber.api.junit.Cucumber.run(Cucumber.java:98) 
     at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367) 
     at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274) 
     at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238) 
     at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161) 
     at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290) 
     at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242) 
     at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121) 
     Caused by: java.lang.reflect.InvocationTargetException 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
     at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:40) 
     ... 33 more 
     Caused by: java.lang.NoClassDefFoundError: org/jdom/Element 
     at myPackageImportFromJar.anotherClass.<clinit> 
     at cucumber.steps.myClass.<init> 
     ... 38 more 
     Caused by: java.lang.ClassNotFoundException: org.jdom.Element 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
     ... 40 more 

只是一個信息(可能是我的錯誤來自於):我使用的jar文件閱讀我想測試項目屬性。

如果您有任何想法,我會很高興聽到它... 謝謝!

+0

看看這個問題:http://stackoverflow.com/a/28387412/1119381。這可能是依賴版本的問題。 –

+0

謝謝你的回答。不幸的是,我已經看到這個問題,在我的情況下,我沒有使用其他任何東西比cucumber-java(1.2.4),cucumber-junit(1.2.4)和junit(4.12)依賴項... –

回答

0

發現問題出在哪裏來自:

我用org.jdom中的依賴和JDOM從未承認,可能永遠不會被實例化(有點怪異,但我無法解釋......)。我使用的解決方案是將jdom依賴性更改爲jdom2依賴性。有了這種依賴關係,一切運作良好(目前)。