如何使用Equinox/OSGi遵循测试优先方法-Tycho-Eclipse RCP环境 [英] How to follow test first approach with Equinox/OSGi - Tycho - Eclipse RCP environment

查看:126
本文介绍了如何使用Equinox/OSGi遵循测试优先方法-Tycho-Eclipse RCP环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入了一个项目,该项目是使用Equinox/OSGi,Tycho在Eclipse RCP平台上进行开发的.

I joined a project where the development is carried on Eclipse RCP platform with the use of Equinox/OSGi, Tycho.

我逐渐熟悉OSGi的类路径/类加载机制,tycho,春分的工作原理等.

I am slowly getting familiar with classpath/classloading mechanism of OSGi, how tycho, equinox works etc.

我正在通过使用模拟来编写简单的单元测试,方法是将它们收集在测试包(目标包的片段)中,但是我遇到ClassNotFound错误,即附加源代码的问题.我已经看到了一些建议,例如将测试作为rcp插件测试运行,或者在集成测试范围内使用tycho.但是,我发现所有这些方法对于运行测试和生产适得其反非常慢.

I am writing plain unit tests with the use of mocking by collecting them in test bundles (which are fragments of the target bundles) however I am encountering ClassNotFound errors, issues with attaching source code. I have seen recommendations such as running tests as rcp plugin tests or with tycho at integration-test scope. However I found all those approaches very slow for running tests and counter-productive.

据我了解,这种环境(Tycho,Eclipse RCP或两者)中的某种程度上的依赖性解析机制与我的假设有些不同.当我将新的实现添加到主机捆绑中以满足我的测试时,除非我为主机捆绑运行mvn install(tycho接管了),否则测试捆绑不会拾取所有新的实现.有时由于缺少依赖项而需要完全安装项目.我尝试的另一种方法是将测试作为JUnit插件测试运行.由于tycho的依赖性解析,该方法也相当慢,并且正在加载所有包.

As far as I understood, somehow dependency resolution mechanism in this environment (Tycho, Eclipse RCP or both) is a bit different than my assumptions. When I add new implementations to the host bundle to satisfy my tests, all the new implementations are not picked up by the test bundle unless I run mvn install (tycho is taking over) for the host bundle. Sometimes that requires full installation of the project because of missing dependencies. Another method I tried was to run tests as JUnit-plugin test. That method is quite slow as well due to dependency resolution of tycho and it is loading all bundles.

我想知道运行单元测试的最佳方法是什么? (当我说单元测试时,我指的是单元测试的真实定义,其中模拟了交互并且测试以毫秒为单位运行).

I would like to know what is the best approach for running unit tests ? (when I say unit tests I mean the true definition of unit tests where interactions are mocked and tests run in miliseconds).

推荐答案

只要您的测试不依赖于OSGi,就可以像在Eclipse中使用 Run as> JUnit Test 一样执行它们.这将在没有OSGi运行时的情况下启动测试,但具有正常的类路径,并且所有捆绑软件均被视为正常的JAR.只要测试和被测代码不需要OSGi运行时中的任何内容(如捆绑软件激活,服务等),此方法就可以使用.

As long as your tests don't depend on OSGi, you can execute them as with Run as > JUnit Test in Eclipse. This will launch the test without an OSGi runtime, but with a normal class path and all bundles treated as normal JARs. This works as long as the test and code under test don't require anything from the OSGi runtime like bundle activation, services, etc.

如果存在这种依赖性,则测试通常会由于未初始化的字段而失败,例如与NPE.在这种情况下,您需要将测试作为 JUnit插件测试在Eclipse中运行.您可以调整这些测试的启动时间

In case there is such a dependency, the test will often fail due to uninitialized fields, e.g. with NPEs. In this case, you'll need to run the tests as JUnit Plug-in test in Eclipse. You can tweak the start-up time of these tests

    通过将要运行的程序更改为运行应用程序,
  • :[无应用程序]-无头模式,和
  • 仅选择运行测试真正需要的那些包.要解决这个问题可能非常复杂,因此如果您不熟悉OSGi,我不建议您这样做.
  • by changing the Program to Run to Run an application: [No Application] - Headless Mode, and
  • by selecting only those bundles that are really needed to run the test. This can be quite complicated to get right, so I wouldn't recommend this if you are new to OSGi.

在完整的Maven/Tycho构建中运行测试通常比在Eclipse中运行测试要慢得多.就个人而言,在将更改推送到中央存储库之前,我只是将其作为输出限定条件.

Running the tests as part of a full Maven/Tycho build is usually a lot slower than running the tests in Eclipse. Personally, I only do this as output qualification before pushing the change into the central repository.

这篇关于如何使用Equinox/OSGi遵循测试优先方法-Tycho-Eclipse RCP环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆