如何有效地JUnit测试Eclipse RCP插件 [英] How to efficiently JUnit test Eclipse RCP Plugins

查看:174
本文介绍了如何有效地JUnit测试Eclipse RCP插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个更大的Eclipse RCP应用程序,并且不确定如何正确测试它的插件.

  • 对于每个插件,都有一个包含单元测试的测试片段.
  • 对于不需要运行RCP平台的较小测试,我们只需调用标准" JUnit测试运行程序即可.

  • 对于需要RCP平台的测试,可以使用JUnit插件测试运行器对其进行测试.

  • 对于JUnit插件测试,可以定义RCP平台启动时要加载哪些插件.

  • 问题:由于RCP平台和所有插件都需要启动,因此运行JUnit插件测试会花费大量时间(对于简单的JUnit Test,这需要几秒钟而不是几毫秒). /p>

  • 问题:如何有效地最小化为测试运行的插件? 我必须采取哪些选择来最大程度地减少对RCP平台的依赖性(例如首选项服务"和扩展点")? 可能有一些模拟库或至少有一些模拟RCP平台服务的最佳实践吗?

现在,我无法想象用JUnit插件测试运行程序来完成一些不错的TDD,执行这些测试只需要太长时间.

非常欢迎您提供有关该主题的任何建议和经验!

解决方案

我能感觉到您的痛苦:进行插件测试很糟糕!而且我也没有找到一个完全令人满意的解决方案.

虽然您可以将所需的插件减少到绝对的最小值而可能会花费几毫秒的时间,但是我发现这是不切实际的,因为依赖关系图中的更改也经常需要调整启动配置.如果在(共享)启动配置中有依赖于平台的片段(即SWT),则情况会变得更糟.我通常会退回到所有工作区并启用目标插件选项,并且启动速度没有明显差异.

我不知道用于RCP平台的模拟库.

除了非常简单的情况外,我不会嘲笑平台的某些部分,因为您很容易就可以将行为弄错.另请参阅此帖子: https://stackoverflow.com/a/31938571/2986905

我的做法是将平台依赖关系尽可能地排除在我的应用程序代码之外,以便我可以编写简单的JUnit测试.平台API上的自定义抽象可以在此处为重复使用案例提供帮助.

此外,在工作台不运行的情况下,可以使用数量惊人的平台API,例如所有SWT和JFace API,首选项,等等.因此,再次编写具有最小依赖关系的小型简单类有助于保持生命力.远离插件测试.例如,将视图的内容与IViewPart(或其等价的e4)分开,可以编写测试而无需视图,而又可以运行一个工作台实例(请原谅,如果我要说明的话).

We have a rather larger Eclipse RCP application and are not sure how to properly test it's plugins.

  • For each plugin, there is a test fragment that contains Unit tests.
  • For smaller tests, that do not require the RCP Platform running, we simply invoke the "standard" JUnit test runner.

  • For tests, that require the RCP Platform, there is the possibility to test it using the JUnit plugin test runner.

  • For the JUnit plugin tests, it is possible to define which plugins are loaded when the RCP Platform starts up.

  • Problem: Running JUnit Plugin Tests takes a lot of time (seconds instead of millicseconds for simple JUnit Test) and resources, since the RCP Platform and all plugins need to start up.

  • Question: How can I efficiently minimize the plugins that are run for the test? What options do I have to minimize my dependencies to the RCP Platform (such as Preferences Service and Extension Points)? Are there maybe some Mocking libraries or at least some best practices for mocking RCP Platform services?

Right now I cannot imagine to do some decent TDD with the JUnit plugin test runner, it just takes too long to execute these tests.

Any advice and experience on that topic very welcome!

解决方案

I can feel your pain: having plug-in tests sucks! And I haven't found a fully satisfying solution either.

While you probably could gain some (milli-?)seconds in that you reduce the required plug-ins to the absolute minimum, I found it impractical as changes in your dependency graph often require to adjust the launch configuration as well. And this gets worse if you have platform dependent fragments (i.e. SWT) in your (shared) launch configurations. I usually fall back to the all workspace and enabled target plug-ins option and haven't seen a notable difference in startup speed.

I am not aware of a mock library for the RCP platform.

Except for very simple cases, I would refrain from mocking parts of the platform as you could easily get the behavior wrong. See also this post: https://stackoverflow.com/a/31938571/2986905

My practice is to keep platform dependencies out of my application code as much as possible so that I can write plain JUnit tests. Custom abstractions over platform APIs can help here for recurring use cases.

In addition, a surprisingly large number of platform APIs can be used without the workbench running, like, of course, all SWT and JFace APIs, preferences, ... Thus writing small, simple classes with minimal dependencies again helps to stay away from plug-in tests. For example, separating the contents of a view from the IViewPart (or its e4 equivalent) allows writing tests without requiring a view and in turn a running workbench instance (pardon if I am stating the obvious).

这篇关于如何有效地JUnit测试Eclipse RCP插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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