I need to use JUnit 4.4 (or newer) in a set of eclipse plugin tests, but I've run into the following problem:
我需要在一组eclipse插件测试中使用JUnit 4.4(或更新),但我遇到了以下问题:
Tests are not detected when running with the junit 4.4 or 4.5 bundles from springsource (junit44 and junit45). The org.junit4 bundle that can be obtained with eclipse supplies junit 4.3 (as of Ganymead / Eclipse 3.4). The org.junit4 bundle does work in that it identifies and runs the tests, but it is not compatible with the latest versions of JMock, and I need to use a mocking library.
从springsource (junit44和junit45)运行junit 4.4或4.5包时,没有检测到测试。org。junit4 bundle可以通过eclipse提供junit 4.3(如Ganymead / eclipse 3.4)。org。junit4 bundle的工作是识别和运行测试,但是它与JMock的最新版本不兼容,我需要使用一个模拟库。
Here is a sample test:
这是一个样本测试:
package testingplugin;
import static org.junit.Assert.*;
import org.junit.Test;
public class ActivatorTest {
@Test
public final void testDoaddTest() {
fail("Not yet implemented");
}
}
When running this test, I receive the following exception:
在运行此测试时,我收到以下异常:
java.lang.Exception: No runnable methods
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:33)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
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:195)
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:382)
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:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
However, if I switch the project dependencies from com.springsource.org.junit to org.junit4, then the test runs and fails (as expected).
但是,如果我将项目依赖项从com.springsource.org.junit切换到org。junit4,然后测试运行并失败(如预期)。
I am running the test as a JUnit Plug-in Test in Eclipse, with the following program arguments:
我将在Eclipse中作为JUnit插件测试运行测试,并使用以下程序参数:
-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}
操作系统$ {目标。os } ws $ {目标。ws }弓$ {目标。弓}问$ { target.nl }
The following plug-ins selected during launch (selected by me, then I used "add required plugins" to get the rest of the dependencies.):
在启动过程中选择的以下插件(由我选择,然后我使用“add required plugins”来获得其他的依赖项):
Workspace:
testingPlugin
Target Platform:
com.springsource.org.hamcrest.core (1.1.0)
com.springsource.org.junit (4.5.0)
....and a bunch of others... (nothing related to testing was auto-selected)
Here is my MANIFEST.MF:
这是我的manifest . mf:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TestingPlugin Plug-in
Bundle-SymbolicName: testingPlugin
Bundle-Version: 1.0.0
Bundle-Activator: testingplugin.Activator
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: com.springsource.org.junit;bundle-version="4.5.0"
Switching the last line to:
将最后一行转换为:
Require-Bundle: org.junit4;bundle-version="4.3.1"
And updating the selected plugins at launch to:
并在启动时更新所选的插件:
Workspace:
testingPlugin
Target Platform:
org.junit4 (4.3.1)
...bunches of auto-selected bundles... (again, nothing else test related)
Causes the test to run properly (but with the wrong version of junit).
使测试运行正常(但使用了错误的junit版本)。
9 个解决方案
#1
4
In my experience this happens if the plugin which contains the plugin tests does not depend on junit. After adding the junit 4.4 dependency to my MANIFEST.MF file the error went away and all tests were executed. The junit dependency should be optional because the plugin usually only needs it for the test code.
在我的经验中,如果包含插件测试的插件不依赖于junit,就会发生这种情况。在添加了junit 4.4对我的清单的依赖之后。MF文件的错误消失了,所有的测试都被执行了。junit依赖项应该是可选的,因为插件通常只需要它作为测试代码。
#2
2
I cannot test this right now as I don't have an Eclipse 3.4 installation handy, but I've run across a similar problem a while ago in (I think) IntelliJ IDEA 7.0.x, and a workaround was to explicitly specify a test runner.
我现在无法测试这个,因为我没有Eclipse 3.4安装,但是我在一段时间之前遇到过类似的问题(我认为)是IntelliJ IDEA 7.0。x和一个变通方法是明确指定一个测试运行器。
With JUnit 4.5:
与JUnit 4.5:
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ActivatorTest {
//...
}
If this does not work you may have more success with org.junit.runners.BlockJUnit4ClassRunner
如果这个方法不奏效,你可能会获得更多的成功。
For JUnit 4.4 I would try org.junit.internal.runners.JUnit4ClassRunner
对于junit4.4,我将尝试org. JUnit .internal.runner . junit4classrunner。
EDIT : not too sure about the com.springsource.
part as I don't use Springsource. From your question it seems that springsource repackages JUnit under com.springsource.org.junit
but you use just org.junit
in your code so I'll stick with that.
编辑:不太确定。springsource。部分因为我不使用Springsource。从您的问题来看,springsource在com.springsource.org.junit中重新打包了JUnit,但是您使用的只是org。在你的代码中有junit,所以我会坚持。
#3
1
I'm wondering whether you might need to import the @Test tag from com.springsource.org.junit and not from org.junit.
我想知道您是否需要从com.springsource.org.junit中导入@Test标记,而不是从org.junit中导入。
Volker
Volker
#4
1
I had some similar sounding problems with jMock, JUnit & Eclipse recently, although admittedly not with plugin tests.
最近,我在jMock、JUnit和Eclipse中遇到了一些类似的问题,但不可否认的是,没有使用插件测试。
I'm not sure if it's relevant, but I got it all working with the following versions :-
我不确定它是否相关,但我得到了它所有的工作与以下的版本:-。
- jmock-2.5.1.jar
- jmock-2.5.1.jar
- hamcrest-core-1.1.jar
- hamcrest-core-1.1.jar
- hamcrest-library-1.1.jar
- hamcrest-library-1.1.jar
- jmock-junit4-2.5.1.jar
- jmock-junit4-2.5.1.jar
I also found I had to use the JMock test runner like this :-
我还发现我必须像这样使用JMock测试runner:-。
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jmock.Mockery;
import org.jmock.Expectations;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.integration.junit4.JMock;
@RunWith(JMock.class)
public class PublisherTest {
Mockery context = new JUnit4Mockery();
@Test
public void oneSubscriberReceivesAMessage() {
#5
0
I don't know which version of JUnit it was, but to succesfully find test the test methods name must start with the word "test".
我不知道它是哪个版本的JUnit,但是为了成功地找到测试方法,名称必须以“test”开头。
In newer version you can simply mark test with @Test, for me it works in this combination:
在新版本中,您可以简单地用@Test标记测试,对我来说,它在这个组合中工作:
import static junit.framework.Assert.*;
...
@Test
public void testDummy() throws Exception
#6
0
Maybe your JUnit bundle is missing an entry in the MANIFEST.MF:
可能您的JUnit包丢失了MANIFEST.MF中的条目:
Dynamic-Import-Package: *
Dynamic-Import-Package:*
This is mandatory to load classes from other bundles.
这是强制从其他包装入类的。
Bebbo
Bebbo
#7
0
ActivatorTest needs to extend TestCase
ActivatorTest需要扩展TestCase。
#8
0
@RunWith(Suite.class) @SuiteClasses( { UserServiceTest.class,ABCServiceTest.class })
@RunWith Suite.class @SuiteClasses({ UserServiceTest.class ABCServiceTest。类})
public class AllTestSuite {
公开课AllTestSuite {
public static Test suite() {
公共静态测试套件(){
return new JUnit4TestAdapter(AllTestSuite .class);
}
}
}
#9
0
I think the spring testing framework is not compatible with junit 4.4+
我认为spring测试框架与junit 4.4+不兼容。
#1
4
In my experience this happens if the plugin which contains the plugin tests does not depend on junit. After adding the junit 4.4 dependency to my MANIFEST.MF file the error went away and all tests were executed. The junit dependency should be optional because the plugin usually only needs it for the test code.
在我的经验中,如果包含插件测试的插件不依赖于junit,就会发生这种情况。在添加了junit 4.4对我的清单的依赖之后。MF文件的错误消失了,所有的测试都被执行了。junit依赖项应该是可选的,因为插件通常只需要它作为测试代码。
#2
2
I cannot test this right now as I don't have an Eclipse 3.4 installation handy, but I've run across a similar problem a while ago in (I think) IntelliJ IDEA 7.0.x, and a workaround was to explicitly specify a test runner.
我现在无法测试这个,因为我没有Eclipse 3.4安装,但是我在一段时间之前遇到过类似的问题(我认为)是IntelliJ IDEA 7.0。x和一个变通方法是明确指定一个测试运行器。
With JUnit 4.5:
与JUnit 4.5:
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ActivatorTest {
//...
}
If this does not work you may have more success with org.junit.runners.BlockJUnit4ClassRunner
如果这个方法不奏效,你可能会获得更多的成功。
For JUnit 4.4 I would try org.junit.internal.runners.JUnit4ClassRunner
对于junit4.4,我将尝试org. JUnit .internal.runner . junit4classrunner。
EDIT : not too sure about the com.springsource.
part as I don't use Springsource. From your question it seems that springsource repackages JUnit under com.springsource.org.junit
but you use just org.junit
in your code so I'll stick with that.
编辑:不太确定。springsource。部分因为我不使用Springsource。从您的问题来看,springsource在com.springsource.org.junit中重新打包了JUnit,但是您使用的只是org。在你的代码中有junit,所以我会坚持。
#3
1
I'm wondering whether you might need to import the @Test tag from com.springsource.org.junit and not from org.junit.
我想知道您是否需要从com.springsource.org.junit中导入@Test标记,而不是从org.junit中导入。
Volker
Volker
#4
1
I had some similar sounding problems with jMock, JUnit & Eclipse recently, although admittedly not with plugin tests.
最近,我在jMock、JUnit和Eclipse中遇到了一些类似的问题,但不可否认的是,没有使用插件测试。
I'm not sure if it's relevant, but I got it all working with the following versions :-
我不确定它是否相关,但我得到了它所有的工作与以下的版本:-。
- jmock-2.5.1.jar
- jmock-2.5.1.jar
- hamcrest-core-1.1.jar
- hamcrest-core-1.1.jar
- hamcrest-library-1.1.jar
- hamcrest-library-1.1.jar
- jmock-junit4-2.5.1.jar
- jmock-junit4-2.5.1.jar
I also found I had to use the JMock test runner like this :-
我还发现我必须像这样使用JMock测试runner:-。
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jmock.Mockery;
import org.jmock.Expectations;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.integration.junit4.JMock;
@RunWith(JMock.class)
public class PublisherTest {
Mockery context = new JUnit4Mockery();
@Test
public void oneSubscriberReceivesAMessage() {
#5
0
I don't know which version of JUnit it was, but to succesfully find test the test methods name must start with the word "test".
我不知道它是哪个版本的JUnit,但是为了成功地找到测试方法,名称必须以“test”开头。
In newer version you can simply mark test with @Test, for me it works in this combination:
在新版本中,您可以简单地用@Test标记测试,对我来说,它在这个组合中工作:
import static junit.framework.Assert.*;
...
@Test
public void testDummy() throws Exception
#6
0
Maybe your JUnit bundle is missing an entry in the MANIFEST.MF:
可能您的JUnit包丢失了MANIFEST.MF中的条目:
Dynamic-Import-Package: *
Dynamic-Import-Package:*
This is mandatory to load classes from other bundles.
这是强制从其他包装入类的。
Bebbo
Bebbo
#7
0
ActivatorTest needs to extend TestCase
ActivatorTest需要扩展TestCase。
#8
0
@RunWith(Suite.class) @SuiteClasses( { UserServiceTest.class,ABCServiceTest.class })
@RunWith Suite.class @SuiteClasses({ UserServiceTest.class ABCServiceTest。类})
public class AllTestSuite {
公开课AllTestSuite {
public static Test suite() {
公共静态测试套件(){
return new JUnit4TestAdapter(AllTestSuite .class);
}
}
}
#9
0
I think the spring testing framework is not compatible with junit 4.4+
我认为spring测试框架与junit 4.4+不兼容。