使用 JUnit4 运行 Ant PDE 测试
我正在尝试使用 pde-maven-plugin、maven 调用或 ant 任务自动化 pde 测试。我按照文章 Automating Eclipse PDE Unit Tests using 的说明进行操作Ant 创建 test.xml
测试失败,首先是因为找不到测试
junit.framework.AssertionFailedError: junit.framework.AssertionFailedError: No tests found in com.example.TestSuite
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
我搜索并发现我应该使用 JUnit4Adapter
,但这样做我得到了 ClassCastException
,这是堆栈跟踪
java.lang.ClassCastException: junit.framework.JUnit4TestAdapter cannot be cast to junit.framework.Test
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:108)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
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:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
这是我的插件依赖项:
Require-Bundle:
org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.core;bundle-version="3.4.2",
org.eclipse.jdt.launching;bundle-version="3.4.1",
org.eclipse.core.resources;bundle-version="3.4.1",
org.apache.xerces;bundle-version="2.9.0",
org.junit4;bundle-version="4.3.1"
测试类
package com.example;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses( { SimpleTests.class})
public class TestSuite {
public static Test suite() {
return new JUnit4TestAdapter(TestSuite.class);
}
}
知道如何修复吗?
I am trying to automate pde tests, using pde-maven-plugin, maven calls, or ant tasks. I followed instructions from the article Automating Eclipse PDE Unit Tests using Ant to create the test.xml
Tests failed, first because No Tests Found
junit.framework.AssertionFailedError: junit.framework.AssertionFailedError: No tests found in com.example.TestSuite
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
I searched and found that I should use JUnit4Adapter
, but doing that I got ClassCastException
, here's the stack trace
java.lang.ClassCastException: junit.framework.JUnit4TestAdapter cannot be cast to junit.framework.Test
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:108)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
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:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Here's my plugin dependencies:
Require-Bundle:
org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.core;bundle-version="3.4.2",
org.eclipse.jdt.launching;bundle-version="3.4.1",
org.eclipse.core.resources;bundle-version="3.4.1",
org.apache.xerces;bundle-version="2.9.0",
org.junit4;bundle-version="4.3.1"
and the test class
package com.example;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses( { SimpleTests.class})
public class TestSuite {
public static Test suite() {
return new JUnit4TestAdapter(TestSuite.class);
}
}
any idea how to fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过在调用 org.eclipse.equinox.launcher.Main 时添加下一行来修复此问题:
这是完整的 java ant 任务:
It is fixed by adding next lines when invoking org.eclipse.equinox.launcher.Main:
Here's the full java ant task:
我遇到了与 Noura 相同的问题,并尝试了他们提供的修复程序,不幸的是,这只解决了部分问题。尽管我的 29 个测试都用
@Test
ClassCastException,而是得到了junit4 java.lang.Exception: No runnablemethod
>。经过几个小时的搜索(并且只在 JUnit 4 新出现时才发现真正的旧错误)和实验(这篇文章也没有帮助),我发现我的修复的第二部分与类路径相关。
我已将我的类路径(用于启动
PDETestResultsCollector
、PDETestPortLocator
和测试插件)定义为:并按以下方式启动它:
事实证明,具有
类路径上的 build/my-bundled-jar-with-tests.jar
混淆了测试运行程序,因此我必须制作一个新的 jar,其中仅包含PDETestListener
的类文件,PDETestPortLocator
和PDETestResultsCollector
(称为 pde-test.jar)。我的固定路径是:找到并运行所有 29 个测试。
I had the same problem as Noura and tried the fix they provided, which, unfortunately, only solved part of the problem. Instead of throwing the aforementioned
ClassCastException
, I gotjunit4 java.lang.Exception: No runnable methods
, despite my 29 tests being carefully annotated with@Test
.After a few hours of searching (and only finding really old bugs back when JUnit 4 was new) and experimenting (this SO post didn't help either), I discovered the second part of my fix was related to the class path.
I had defined my classpath (which was used to launch
PDETestResultsCollector
,PDETestPortLocator
and the test plugin) to be:and launched it like:
As it turns out, having
build/my-bundled-jar-with-tests.jar
on the classpath confused the test runner, so I had to make a new jar that contained just class files forPDETestListener
,PDETestPortLocator
andPDETestResultsCollector
(called pde-test.jar). My fixed path was:And all 29 tests were found and ran.