java OSGi 测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/73881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OSGi Testing
提问by fluffels
Currently, I am working on a new version control system as part of a final year project at University. The idea is to make it highly adaptable and pluggable.
目前,我正在研究一个新的版本控制系统,作为大学最后一年项目的一部分。这个想法是让它具有高度的适应性和可插拔性。
We're using the OSGi framework (Equinox implementation) to manage our plug ins. My problem is that I can't find a simple & easy to use method for testing OSGi bundles.
我们使用 OSGi 框架(Equinox 实现)来管理我们的插件。我的问题是我找不到一种简单易用的方法来测试 OSGi 包。
Currently, I have to build the bundle using Maven and then execute a test harness. I'm looking for something like the JUnit test runner for Eclipse, as it will save me a bunch of time.
目前,我必须使用 Maven 构建包,然后执行测试工具。我正在寻找类似用于 Eclipse 的 JUnit 测试运行程序的东西,因为它可以为我节省大量时间。
Is there a quick and easy way to test OSGi bundles?
有没有一种快速简便的方法来测试 OSGi 包?
EDIT: I don't need something to test Eclipse plug ins or GUI components, just OSGi bundles.
编辑:我不需要测试 Eclipse 插件或 GUI 组件的东西,只需要 OSGi 包。
EDIT2: Is there some framework that supports JUnit4?
EDIT2:是否有一些支持 JUnit4 的框架?
采纳答案by flicken
Spring Dynamic Modules has excellent support for testing OSGi bundles.
Spring Dynamic Modules 对测试 OSGi 包有很好的支持。
回答by Luca Geretti
More recently, you should have a look at Pax Exam: http://team.ops4j.org/wiki/display/paxexam/Pax+Exam
最近,你应该看看 Pax Exam:http: //team.ops4j.org/wiki/display/paxexam/Pax+Exam
This is the current effort at OPS4J related to testing.
这是 OPS4J 当前与测试相关的工作。
回答by rescdsk
Here are some tools not mentioned yet:
以下是一些尚未提及的工具:
I'm using Tycho, which is a tool for using Maven to build Eclipse plugins. If you create tests inside their own plug-ins, or plug-in fragments, Tycho can run each set of tests inside its own OSGi instance, with all its required dependencies. Introand further info. This is working quite well for me.
jUnit4OSGIlooks straightforward. You make subclasses of OSGiTestCase, and you get methods like
getServiceReference(), etc.Pluginbuilder, a headless build system for OSGi bundles / Eclipse plug-ins, has a test-running frameworkcalled Autotestsuite. It runs the tests in the context of the OSGi environment, after the build step. But, it doesn't seem to have been maintained for several years. I think that many Eclipse projects are migrating from Pluginbuilder to Tycho.
Another option is to start an instance of an OSGi container withinyour unit test, which you run directly, as explained here.
Here's someone who's written a small bundle test collector, which searches for JUnit (3) tests and runs them.
我正在使用Tycho,这是一个使用 Maven 构建 Eclipse 插件的工具。如果您在他们自己的插件或插件片段中创建测试,Tycho 可以在其自己的 OSGi 实例中运行每组测试,以及所有必需的依赖项。 介绍和更多信息。这对我来说效果很好。
jUnit4OSGI看起来很简单。您创建 OSGiTestCase 的子类,并获得诸如
getServiceReference()等的方法。Pluginbuilder是一个用于 OSGi 包/Eclipse 插件的无头构建系统,有一个名为Autotestsuite的测试运行框架。在构建步骤之后,它在 OSGi 环境的上下文中运行测试。但是,它似乎并没有被维护好几年。我认为许多 Eclipse 项目正在从 Pluginbuilder 迁移到 Tycho。
另一种选择是开始的一个实例,一个OSGi容器内的单元测试,你直接运行,如解释在这里。
这是一个写了一个小的bundle test collector 的人,它搜索 JUnit (3) 测试并运行它们。
回答by Toni Menzel
There is a dedicated open source OSGi testing framework on OPS4J (ops4j.org) called Pax Drone.
OPS4J (ops4j.org) 上有一个专用的开源 OSGi 测试框架,称为Pax Drone。
You might want to have a look at Pax Drone ([http://wiki.ops4j.org/confluence/x/KABo]) which enables you to use all Felix Versions as well as Equinox and Knopflerfish in your tests.
您可能想看看 Pax Drone ([ http://wiki.ops4j.org/confluence/x/KABo]),它使您能够在测试中使用所有 Felix 版本以及 Equinox 和 Knopflerfish。
Cheers, Toni
干杯,托尼
回答by Rafael Chaves
Eclipse has a launch configuration type for running JUnit tests in the context of an Eclipse (i.e. OSGi) application:
Eclipse 有一个启动配置类型,用于在 Eclipse(即 OSGi)应用程序的上下文中运行 JUnit 测试:
回答by Rafael Chaves
回答by Basy
For unit tests use the EasyMock framework or create your own implementations of the required interfaces for testing .
对于单元测试,请使用 EasyMock 框架或创建您自己的测试所需接口的实现。
回答by pooh
The ProSyst Test Execution Environmentis a useful test tool for OSGi bundles. It also supports JUnit tests as one of the possible test models.
该ProSyst测试执行环境是OSGi包一个有用的测试工具。它还支持 JUnit 测试作为可能的测试模型之一。
回答by user33790
回答by Balazs Zsoldos
I think we met the same issue and we made our own solution. There are different parts of the solution:
我认为我们遇到了同样的问题,我们制定了自己的解决方案。解决方案有不同的部分:
- A junit4runner that catches all OSGi services that has a special property defined. It runs these caught services with JUnit4 engine. JUnit annotations should be placed into interfaces that the services implement.
- A maven plugin that starts an OSGi framework (a custom framework can be created as maven dependency) and runs the unit tests inside the integration-test maven lifecycle.
- A deployer OSGi bundle. If this is dropped into your OSGi container a simple always-on-top window will be opened where you can drop your project folders (from total commander or from eclipse). This will then redeploy that bundle.
- 一个 junit4runner,它捕获所有定义了特殊属性的 OSGi 服务。它使用 JUnit4 引擎运行这些捕获的服务。JUnit 注释应该放在服务实现的接口中。
- 一个 maven 插件,它启动一个 OSGi 框架(可以创建一个自定义框架作为 maven 依赖项)并在集成测试 maven 生命周期内运行单元测试。
- 一个部署者 OSGi 包。如果将其放入您的 OSGi 容器中,将打开一个简单的始终在顶部的窗口,您可以在其中放置项目文件夹(来自 totalcommander 或来自 eclipse)。这将重新部署该捆绑包。
With the tools you can do TDD and have the written tests always run inside the maven integration-phase as well. It is recommended to use eclipse with m2e and maven-bundle-plugin as in this case the target/classes/META-INF/MANIFEST.MF is regenerated as soon as you save a class in your source so you can drag the project and drop to the deployer window. The OSGi bundles you develop do not have to have any special feature (like being an eclipse plugin or something).
使用这些工具,您可以执行 TDD,并使书面测试始终在 Maven 集成阶段内运行。建议将 eclipse 与 m2e 和 maven-bundle-plugin 一起使用,因为在这种情况下,只要在源中保存类,就会重新生成 target/classes/META-INF/MANIFEST.MF,以便您可以拖放项目到部署器窗口。您开发的 OSGi 包不必具有任何特殊功能(例如是 Eclipse 插件或其他东西)。
The whole solution is OpenSource. You can find a tutorial at http://cookbook.everit.org
整个解决方案是开源的。您可以在http://cookbook.everit.org 上找到教程

