2015-04-16 56 views
1

我有一個項目可以做一些硒測試。測試位於「src/test/java」文件夾中。當我嘗試使用maven構建項目(選項:clean install)時,出現構建錯誤。爲什麼build的成功取決於文件夾名稱? (maven/selenium)

但是,當我將文件夾重命名爲「src/testExec/java」或與「src/test/java」不同的任何其他路徑時,構建過程完成而沒有發生錯誤。

爲什麼?我想保留標準命名約定「src/test/java」。

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.215s 
[INFO] Finished at: Thu Apr 16 09:32:46 CEST 2015 
[INFO] Final Memory: 30M/72M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project variant: There are test failures. 
[ERROR] 
[ERROR] Please refer to C:\Users\cschneid\Desktop\Projekt\workspaceCalc\Calculator\CalculatorModuleMain\target\surefire-reports for the individual test results. 
[ERROR] -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project variant: There are test failures. 

Please refer to C:\Users\cschneid\Desktop\Projekt\workspaceCalc\Calculator\CalculatorModuleMain\target\surefire-reports for the individual test results. 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
    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:601) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures. 

Please refer to C:\Users\cschneid\Desktop\Projekt\workspaceCalc\Calculator\CalculatorModuleMain\target\surefire-reports for the individual test results. 
    at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:87) 
    at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:641) 
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:615) 
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:137) 
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:98) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
    ... 19 more 
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

在位置 「C:\用戶\ cschneid \桌面\ Projekt的\ workspaceCalc \計算器\ CalculatorModuleMain \目標\萬無一失的報告」 是:

------------------------------------------------------------------------------- 
Test set: calc.repository.RepositoryTest 
------------------------------------------------------------------------------- 
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.078 sec <<< FAILURE! 
calc.repository.RepositoryTest Time elapsed: 0 sec <<< ERROR! 
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95) 
    at calc.repository.RepositoryTest.initWebDriver(RepositoryTest.java:24) 
    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:601) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) 
    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:601) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) 
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) 
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) 
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
    ... 27 more 
calc.repository.RepositoryTest Time elapsed: 0.002 sec <<< ERROR! 
java.lang.NullPointerException 
    at calc.repository.RepositoryTest.theEnd(RepositoryTest.java:29) 
    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:601) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) 
    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:601) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) 
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) 
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) 
+0

C:\ Users \ cschneid \ Desktop \ Projekt \ workspaceCalc \ Calculator \ CalculatorModuleMain \ target \ surefire-reports log?可能你的測試期望src/testExec路徑? 「testExec」是否可以改變,並仍然有效? – exoddus

+0

maven的測試類應該位於/ src/test/java(不只是src/test)https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html – exoddus

+0

它在/ src/test/java,/ src/testExec/java中。 – gartenkralle

回答

0

如果你的測試都位於另一個目錄比標準的src /測試/ java目錄,可以改變其在pom.xml

定義例如testSourceDirectory配置參數的默認值:

<build> 
    <testSourceDirectory>src/testExec/java</testSourceDirectory> 
</build> 

如果它在您更改測試類位置時起作用,似乎測試不會執行並且對您來說似乎沒有問題,但它們可能不會。

嘗試在您的pom.xml中指定testSourceDirectory屬性以指向您的實際測試文件夾。然後再次檢查測試是否正確執行。

如果我是正確的,測試將以相同的失敗,當你把你的測試中(SRC /測試/ JAVA)的,你應該解決在

Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException 

所示的問題...

calc.repository.RepositoryTest Time elapsed: 0.002 sec <<< ERROR! 
java.lang.NullPointerException 
    at calc.repository.RepositoryTest.theEnd(RepositoryTest.java:29) 

我想目前未使用的文件夾名稱一個問題,似乎是一個問題,只是你的測試類,但是如果你把你的測試在一個非標準的文件夾(如testExec或whtaever你想要的),行家跳過測試執行和構建是可以的。

相關問題