测试 OSGi 包的快速简便方法
目前,我正在开发一个新的版本控制系统,作为大学最后一年项目的一部分。 我们的想法是使其具有高度适应性和可插拔性。
我们使用 OSGi 框架(Equinox 实现)来管理我们的插件。 我的问题是我找不到一个简单的 & 用于测试 OSGi 包的易于使用的方法。
目前,我必须使用 Maven 构建捆绑包,然后执行测试工具。 我正在寻找类似 Eclipse 的 JUnit 测试运行器之类的东西,因为它会节省我大量的时间。
有没有一种快速、简单的方法来测试 OSGi 包?
编辑:我不需要测试 Eclipse 插件或 GUI 组件的东西,只需要 OSGi 包。
EDIT2:是否有支持 JUnit4 的框架?
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.
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.
Is there a quick and easy way to test OSGi bundles?
EDIT: I don't need something to test Eclipse plug ins or GUI components, just OSGi bundles.
EDIT2: Is there some framework that supports JUnit4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
我想有很多方法可以测试 OSGi 组件。 进行测试的一种方法是使用 Robot Framework。 我所做的是使用 Robot Framework 进行测试,并将远程库安装在 OSGi 中,或者让它们通过套接字与 OSGi 测试组件通信,机器人将与这些模块通信并通过它们运行测试。
因此,基本上您的 OSGi 模块应该具有执行某些操作并产生一些输出的接口。 因此,在我的设置中,我有一个测试组件,它会对实际的 OSGi 组件进行服务调用,然后会有一个侦听服务来捕获事件/服务调用(由被测模块进行),这些结果可以被机器人询问。 因此,基本上通过这种方式,您可以将大型系统拆分为小组件,并使系统在生产/生产环境中运行,并在组件级别自动测试或对一些实际组件进行统一测试。
There are many ways to test OSGi components, I suppose. One way of doing the testing is to use Robot Framework. What I've done is made my tests with Robot Framework and have the remote libraries either installed in OSGi or have them talk to OSGi-test components through sockets and robot would talk to these modules and run tests through them.
So, basically your OSGi-modules should have interfaces that do something and produce some output. So, in my setup I had a test components that would make service calls to the actual OSGi-component and then there would be a listening-service that would catch the events/service calls (made by the module under test) and those results could be asked by the robot. So basically this way you can split a massive system in small components and have the system run in production/production like enviroment and have it tested automatically on component level or have some of the real components be tested in unison.
在过去几年中,Tycho(一种新的基于 Maven 的 OSGi 构建系统)在 Eclipse 中变得相当流行基础。 该框架还包括使用 Maven Surefire 在单独的测试平台中测试 OSGi 包的方法...
During the last couple of years Tycho - a new Maven based build system for OSGi - has become rather popular among the Eclipse Foundation. This framework also includes method to use Maven Surefire to test OSGi bundles in separate testbeds...
最近,您应该看看 Pax Exam:
http://team.ops4j.org/wiki/display/paxexam/Pax+Exam
这是 OPS4J 当前与测试相关的工作。
More recently, you should have a look at Pax Exam:
http://team.ops4j.org/wiki/display/paxexam/Pax+Exam
This is the current effort at OPS4J related to testing.
以下是一些尚未提及的工具:
我正在使用 Tycho,这是一个工具使用 Maven 构建 Eclipse 插件。 如果您在自己的插件或插件片段中创建测试,Tycho 可以在其自己的 OSGi 实例及其所有必需的依赖项中运行每组测试。 介绍 和 更多信息。 这对我来说效果很好。
jUnit4OSGI 看起来很简单。 您创建 OSGiTestCase 的子类,并获得诸如
getServiceReference()
等方法。Pluginbuilder ,一个用于 OSGi 包/Eclipse 插件的无头构建系统,有一个测试 -运行名为Autotestsuite的框架。 在构建步骤之后,它在 OSGi 环境的上下文中运行测试。 不过,好像已经好几年没有维护了。 我认为许多 Eclipse 项目正在从 Pluginbuilder 迁移到 Tycho。
另一个选项是在单元测试中启动一个 OSGi 容器的实例,您可以直接运行该实例,如 此处。
这里有人写了一个小捆绑测试收集器,它搜索 JUnit (3) 测试并运行它们。
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. Intro and further info. This is working quite well for me.
jUnit4OSGI looks 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 framework called 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 within your 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.
Spring 动态模块对测试 OSGi 包提供了出色的支持。
Spring Dynamic Modules has excellent support for testing OSGi bundles.
OPS4J (ops4j.org) 上有一个名为 Pax Drone 的专用开源 OSGi 测试框架。
您可能想看看 Pax Drone ([http://wiki.ops4j.org/ confluence/x/KABo]),它使您能够在测试中使用所有 Felix 版本以及 Equinox 和 Knopflerfish。
干杯,
托尼
There is a dedicated open source OSGi testing framework on OPS4J (ops4j.org) called 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.
Cheers,
Toni
Eclipse 有一个启动配置类型,用于在 Eclipse(即 OSGi)应用程序的上下文中运行 JUnit 测试:
http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc。用户/指南/工具/启动器/junit_launcher.htm
Eclipse has a launch configuration type for running JUnit tests in the context of an Eclipse (i.e. OSGi) application:
http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/launchers/junit_launcher.htm
如果您需要测试 GUI 组件,我发现 SWTBot 可以完成工作。
If you need to test GUI components I've found SWTBot gets the job done.
Treaty 是一个合约(测试)框架,非常学术化,但有一些不错的想法。 已经发表了一些关于它的论文,并且人们目前正在致力于改进它。
Treaty is a contract(testing) framework that is pretty academic but has some nice ideas. There are papers that are published on it, and the people currently working on improving it.
ProSyst 测试执行环境是一个OSGi 包的有用测试工具。 它还支持 JUnit 测试作为可能的测试模型之一。
The ProSyst Test Execution Environment is a useful test tool for OSGi bundles. It also supports JUnit tests as one of the possible test models.
对于单元测试,请使用 EasyMock 框架或创建您自己的测试所需接口的实现。
For unit tests use the EasyMock framework or create your own implementations of the required interfaces for testing .
我认为我们遇到了同样的问题并提出了自己的解决方案。 该解决方案有不同的部分:
使用这些工具,您可以执行 TDD 并让书面测试始终在 Maven 集成阶段内运行。 建议将 eclipse 与 m2e 和 maven-bundle-plugin 一起使用,因为在这种情况下,一旦您在源中保存类,target/classes/META-INF/MANIFEST.MF 就会重新生成,以便您可以拖放项目到部署程序窗口。 您开发的 OSGi 包不必具有任何特殊功能(例如 Eclipse 插件或其他东西)。
整个解决方案是开源的。 您可以在 http://cookbook.everit.org 找到教程
I think we met the same issue and we made our own solution. There are different parts of the solution:
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).
The whole solution is OpenSource. You can find a tutorial at http://cookbook.everit.org
bnd-testing-maven-plugin 怎么样?
它允许在 Felix 或 Equinox 等正在运行的容器内运行 JUnit。
如果您使用 BNDTools for eclipse,这非常相似,但只是没有 eclipse 且没有 UI 的 Maven。
https://github.com/bndtools/bnd/ tree/master/maven/bnd-testing-maven-plugin
还可以查看 maven 的 effectiveosgi 原型。 这将为您构建项目或添加测试提供一个良好的起点。
https://github.com/ effectiveosgi
How about bnd-testing-maven-plugin?
It allow running JUnit inside a running container like Felix or Equinox.
If you used the BNDTools for eclipse this is very similar but just maven withpout eclipse and without a UI.
https://github.com/bndtools/bnd/tree/master/maven/bnd-testing-maven-plugin
also look at the effectiveosgi archetype for maven. This will give you a good starting point to build your project or just add tests.
https://github.com/effectiveosgi
与其他人一起提到,mockito 对于模拟插件依赖项(引用等)非常方便。 请参阅 https://www.baeldung.com/mockito-annotations
Along with others mentioned mockito is very handy to mock plugin dependencies(references etc). see https://www.baeldung.com/mockito-annotations