2015-05-27 33 views
0

我有一個OSGI包,現在想爲它創建一個測試包。由於現有的捆綁包使用Tycho,我還想通過使用tycho-surefire-plugin來測試Eclipse/Tycho-way。Maven tycho-surefire-plugin失敗,返回代碼13

據我所知,測試Eclipse-way意味着,每個bundle都有一個對應的包含所有相關測試用例的包。

所以我創建了一個新的捆綁 「xyz.tests」 具有以下POM:

<artifactId>xyz.tests</artifactId> 
    <packaging>eclipse-test-plugin</packaging> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.eclipse.tycho</groupId> 
       <artifactId>tycho-surefire-plugin</artifactId> 
       <version>0.21.0</version> 
      </plugin> 
     </plugins> 
    </build> 

我也創建了第谷/ OSGI項目的其它標準文件 META-INF/MANIFEST.MF

Manifest-Version: 1.0 
Bundle-ManifestVersion: 2 
Bundle-Name: %Bundle-Name 
Bundle-SymbolicName: xyz 
Bundle-Version: 0.0.1.qualifier 
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 
Fragment-Host: zyx 
Import-Package: org.junit;version="4.11.0" 
Bundle-ActivationPolicy: lazy 

build.properties

output.. = bin/ 
source.. = src/ 
bin.includes = META-INF/,\ 
      OSGI-INF/,\ 
      . 

和OSGI-INF/L10N/bundle.properties

# META-INF/MANIFEST.MF 
Bundle-Name=XYZ Tests 

然後我寫了一個「測試案例」因爲我首先要檢查是否配置了我的Eclipse的測試插件正確

package xyz.tests.xyz; 

import static org.junit.Assert.assertEquals; 
import org.junit.Test; 

public class XYZTest { 

    @Test 
    public void testClasstest() { 
     assertEquals("Tests", true, true); 
    } 
} 

當我運行MVN包爲目標,一切編譯和打包沒有錯誤。然後我運行mvn integration-test作爲目標(這是tycho-surefire開始工作的部分)。在那裏,我得到一個錯誤消息提供任何有用的信息,對我來說:

[INFO] --- tycho-surefire-plugin:0.21.0:test (default-test) @ xyz.tests --- 
[INFO] Expected eclipse log file: /pathXYZ/target/work/data/.metadata/.log 
[INFO] Command line: 
    [/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java, -Dosgi.noShutdown=false, -Dosgi.os=linux, -Dosgi.ws=gtk, -Dosgi.arch=x86_64, -Dosgi.clean=true, -jar, /home/erdi/.m2/repository/p2/osgi/bundle/org.eclipse.equinox.launcher/1.3.0.v20130327-1440/org.eclipse.equinox.launcher-1.3.0.v20130327-1440.jar, -data, /pathXYZ/target/work/data, -install, /pathXYZ/target/work, -configuration, /pathXYZ/target/work/configuration, -application, org.eclipse.tycho.surefire.osgibooter.headlesstest, -testproperties, /pathXYZ/target/surefire.properties] 
xyz: Hello World!! 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
xyz: Goodbye World!! 
An error has occurred. See the log file 
/pathXYZ/target/work/configuration/1432736234573.log. 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 26.050s 
[INFO] Finished at: Wed May 27 16:17:16 CEST 2015 
[INFO] Final Memory: 69M/362M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.21.0:test (default-test) on project xyz.tests: An unexpected error occured (return code 13). See log for details. -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 

的「XYZ:你好/再見世界」的消息時,包我想測試開始被印刷信息/停止。這意味着,當軟件包啓動時,我的配置似乎沒有問題,但在發生錯誤後立即出現。不幸的是尋找到日誌文件還顯示沒有什麼用處:

!SESSION 2015-05-27 16:17:14.238 ----------------------------------------------- 
eclipse.buildId=unknown 
java.version=1.7.0_75 
java.vendor=Oracle Corporation 
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US 
Framework arguments: -application org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties /pathXYZ/target/work/data -application org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties /pathXYZ/target/surefire.properties 

!ENTRY org.eclipse.osgi 4 0 2015-05-27 16:17:15.891 
!MESSAGE Application error 
!STACK 1 
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null 
java.lang.reflect.InvocationTargetException 
    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: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.runSuitesInProcess(SurefireStarter.java:123) 
    at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:87) 
    at org.eclipse.tycho.surefire.osgibooter.HeadlessTestApplication.run(HeadlessTestApplication.java:21) 
    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.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587) 
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198) 
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) 
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354) 
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181) 
    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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636) 
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591) 
    at org.eclipse.equinox.launcher.Main.run(Main.java:1450) 
    at org.eclipse.equinox.launcher.Main.main(Main.java:1426) 
Caused by: java.lang.NullPointerException 
    at java.lang.Class.getAnnotation(Class.java:3217) 
    at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.isValidJUnit4Test(JUnit4TestChecker.java:63) 
    at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept(JUnit4TestChecker.java:52) 
    at org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses(DefaultDirectoryScanner.java:80) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:174) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:83) 
    ... 28 more 

所以我知道一個空指針異常的發生,但我不知道爲什麼/哪裏。

我認爲這將真正幫助看看這背後隱藏着整個錯誤路徑「...... 28多」,但我不知道怎麼看的呢?

我也不能完全確定如果我正確地配置了一切,因爲我沒有找到有用的教程,並且或多或少地查看了其他eclipse項目的測試代碼庫。

回答

1

我終於找到了我的問題的根源:

我所用,此問題將被報告爲一個bug(https://bugs.eclipse.org/bugs/show_bug.cgi?id=369266),並得到了固定,第谷v0.22.0第谷v0.21.0。

更改爲tycho-surefire插件的版本屬性解決了問題。

相關問題