JUnit4Provider不起作用

时间:2016-01-07 11:57:52

标签: tycho

我正在尝试使用打包类型eclipse-test-plugin来实现项目(我有一个雄心勃勃的目标是让它有一天执行测试,但是现在只有两个类中包含空测试方法)。

我认为问题只存在,因为我们使用目标配置文件,因此需要的插件(或其他)不会自动加载。在没有最新文档或示例的情况下,我猜测这样一个用例的 pom.xml 看起来应该是这样的:

<dependencies>
    <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit4</artifactId>
        <version>${see.below}</version>
    </dependency>
</dependencies>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-surefire-plugin</artifactId>
            <version>0.22.0</version>
            <configuration>
                <providerHint>junit4</providerHint>
            </configuration>
        </plugin>
    </plugins>
</build>

(因为没有依赖关系,我得到了ClassNotFoundException: org.apache.maven.surefire.junit4.JUnit4Provider,而这就是班级所在的位置。)

现在,如果我使用surefire-junit4版本2.18.1或更低版本,我会收到以下错误:

An error has occurred. See the log file C:\workspaces\workspace\org.acme.project.rxp-build\org.acme.project.rxp.it\target\work\data\.metadata\.log.
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.22.0:test (default-test) on project org.acme.project.rxp.it: An unexpected error occured while launching the test runtime (return code 13). See log for details. -> [Help 1]

Aaand有问题的日志文件包含:

org.apache.maven.surefire.util.SurefireReflectionException: java.lang.ClassNotFoundException: org.apache.maven.surefire.junit4.JUnit4Provider
at org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:251)
at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:128)
at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:235)
at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:113)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:78)
at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:91)
at org.eclipse.tycho.surefire.osgibooter.HeadlessTestApplication.run(HeadlessTestApplication.java:21)

如果我使用2.19的版本surefire-junit4,我会收到以下消息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (test) on project org.acme.project.rxp.it: Execution test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: There was an error in the forked process
[ERROR] org.apache.maven.surefire.util.SurefireReflectionException: java.lang.NoSuchMethodError: org.apache.maven.surefire.providerapi.ProviderParameters.isInsideFork()Z
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:134)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.createProviderInCurrentClassloader(ForkedBooter.java:230)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:199)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[ERROR] Caused by: java.lang.NoSuchMethodError: org.apache.maven.surefire.providerapi.ProviderParameters.isInsideFork()Z
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.<init>(JUnit4Provider.java:103)
[ERROR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[ERROR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[ERROR] at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:130)

我有点怀疑surefire-apisurefire-junit4有相同的版本,所以我确保Maven为这两个版本加载相同的版本,但行为没有变化。

这里有什么问题?如何让测试插件构建?

2 个答案:

答案 0 :(得分:1)

好吧,如果目标平台文件包含

,它可以在没有愚蠢的Maven依赖项的情况下工作
<unit id="org.hamcrest.core" version="0.0.0"/>
<unit id="org.junit" version="0.0.0"/>
<unit id="org.eclipse.jdt.junit.runtime" version="0.0.0"/>
<unit id="org.eclipse.jdt.junit4.runtime" version="0.0.0"/>

Manifest.MF 包含

Require-Bundle: org.eclipse.jdt.junit4.runtime,
 org.junit

答案 1 :(得分:0)