我应该在哪里放置Eclipse插件片段的testcode? [英] Where should I put testcode for an Eclipse plugin fragment?

查看:189
本文介绍了我应该在哪里放置Eclipse插件片段的testcode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索Eclipse插件测试代码的最佳实践的过程中,我发现了几个帖子。他们大多数建议片段,如这个

There are several posts I found while searching for best practice of where to put test code for an Eclipse plugin. Most of them suggest fragments like this

我有一个单独的插件,它有两个片段,一个用于RCP,一个用于RAP。

I have a plugin single sourced and it has two fragments, one for RCP and one for RAP.

现在,如果我创建另一个测试片段,我无法从测试片段中访问RCP片段API。

Now if I create another fragment for testing I cannot access the RCP fragment API from the test fragment.

有一个标题 Eclipse-ExtensibleAPI ,如果设置为true,则主机插件将使其片段API可用。但它可用于需要它的其他插件,而不是其自己的片段(测试片段)。

There is a header Eclipse-ExtensibleAPI, if set to true the host plugin will make its fragment APIs available. But it's available to other plugins that require it, not its own fragment(the test fragment).

任何人都可以帮助我吗?

Can anyone please help me on this?

推荐答案

是Eclipse测试在单独项目中进行测试的结果。这种分离的目的是从主项目中排除测试依赖关系,如JUnit,嘲笑框架等。然而,这种推理是基于变得越来越过时的假设。如果您不使用PDE构建和插件测试,您可以考虑将测试移动到包含源代码的相同项目中。

This problem is a consequence of the Eclipse convention to put tests in separate projects. The purpose of this separation is to exclude test dependencies like JUnit, mocking frameworks, etc. from the main project. However, this reasoning is based on assumptions that become more and more obsolete. If you neither use PDE build nor plug-in tests, you might consider moving the tests into the same project that contains the source code.

我相信单元测试>属于到项目的源代码,不应该分开。检查源代码的每个人也应该有测试。

I believe that unit tests belong to the source code of a project and should not be separated. Everyone who checks out the source code should also have the tests.

Eclipse插件项目以前是通过 PDE构建构建的,它从Manifest文件读取依赖关系,无法区分测试 - 范围和编译范围的依赖关系。虽然PDE构建仍然在IDE中用于导出,但在大多数Eclipse项目中已被 tycho 替代,包括平台本身Tycho基于Maven,它允许测试范围的依赖关系不会被完成到构建的工件中。

Eclipse plug-in projects used to be built with PDE build which reads dependencies from the Manifest file and cannot distinguish between test-scoped and compile-scoped dependencies. While PDE build is still used inside the IDE for exporting, it has been replaced by tycho in most Eclipse projects including the platform itself. Tycho is based on Maven which allows for test-scoped dependencies that do not end up into the built artifact.

如果将测试移动到主项目中,您可以添加测试与项目构建路径的依赖关系,或查看是否可以使用 m2e 来管理依赖关系。

If you move the tests into the main project, you could add the test dependencies to the project build path or see if you can use m2e to manage dependencies.

导致测试分离的另一个假设是所有测试都执行为所谓的插件测试。插件测试需要运行OSGi环境,它们可以被认为是比单元测试更多的集成测试。这些测试不应该需要访问片段的内部,而是使用环境中可用的片段来测试主机包的功能。

Another assumption that lead to the separation of tests was that all tests are executed as so called plug-in tests. Plug-in tests require a running OSGi environment, they can be considered more integration tests than unit tests. Those tests should not need to access the internals of a fragment, but test the functionality of the host bundle with either fragment available in the environment.

单元测试不应该需要OSGi环境,因此他们使用相同的类加载器,因此不需要保留碎片。如果你使用tycho来构建,你必须使用maven-surefire而不是tycho-surefire,因为后者会执行测试作为插件测试。

Plain unit tests should not require an OSGi environment, hence they use the same classloader anyway and therefore don't need to be kept in fragments. If you build with tycho, you have to use maven-surefire instead of tycho-surefire, as the latter executes tests as plug-in tests.

这篇关于我应该在哪里放置Eclipse插件片段的testcode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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