【发布时间】:2012-08-17 20:44:34
【问题描述】:
我的一个项目中遇到了一些奇怪的问题。我正在尝试在 OSGi 环境中运行一些 JUnit 测试(测试位于由 osgi 包托管的片段中;使用 eclipse 中的“JUnit Plug-in Test”启动器启动操作)。当我尝试启动测试时,出现以下错误:
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
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:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
An error has occurred. See the log file
在上面的日志中我也得到:
!ENTRY org.eclipse.osgi 2 0 2012-08-22 13:53:24.058
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2012-08-22 13:53:24.059
!MESSAGE Bundle reference:file:/C:/.../plugins/org.eclipse.pde.junit.runtime_3.4.200.v20120530-1435.jar was not resolved.
!SUBENTRY 2 org.eclipse.pde.junit.runtime 2 0 2012-08-22 13:53:24.059
!MESSAGE Missing required bundle org.eclipse.core.runtime_[3.3.0,4.0.0).
但是,org.eclipse.core.runtime 似乎可用(eclipse 运行没有任何问题,我可以使用 OSGi 运行启动项目)。根据“Eclipse 安装详细信息”,核心运行时版本为 3.8.0.v20120521-2346,在 junit 所需的正确范围内([3.3.0,4.0.0))。
我还有另一个相同的 Eclipse(相同的版本等...它来自相同的 .zip 存档),我可以在其中为另一个项目运行相同类型的测试。我检查了配置,但没有发现任何区别。因此,我目前无法理解导致此问题的原因。
非常感谢任何可以帮助我解决这个问题的想法,
【问题讨论】:
-
你是在使用junit进行单元或服务间集成测试吗?对于单元测试,您应该不依赖于 OSGi 子系统。对于后者,有几种选择...
-
感谢您的回答。我当前尝试运行的测试仅调用主机包的内部例程。我没有尝试进行服务间集成,但我不确定它会对我当前的问题产生多大影响。确实,我的错误似乎来自尝试使用核心运行时但没有找到它的 eclipse junit 插件(“org.eclipse.pde.junit.runtime”)。
-
您是使用 junit 运行器还是使用“Junit Plug-in Test”运行器运行 junit 测试?您不应该在简单的 Junit 测试中参与 osgi 环境。
-
我真的很抱歉,因为我可能意识到我的第一个解释并不好。我正在使用“Junit Plug-in Test”运行程序运行它。我正在测试一个 OSGi 应用程序,并且我使用了一个由我想要测试的包托管的测试片段。我的测试不完全涉及服务间集成,但我需要在 OSGi 环境中。我已经多次以这种方式测试过 OSGi 应用程序,没有任何问题。
-
好吧,我不使用激活器,因为我更喜欢 DS 注入。对于资源定位,您可以使用
public void activate(ComponentContext context)版本的 activate 方法向您的服务注入模拟上下文。