用于 Eclipse 插件开发的自动化单元测试 (junit)
我正在开发 Eclipse 插件,我需要能够自动构建和执行每个插件的测试套件。 (使用 Junit)
测试在 Eclipse 中进行,我可以将插件分解为实际插件和用于单元测试的片段插件,如所述 此处,这里和几个地方此处。
但是,上述每种方法都会导致相同的问题:发出构建或应该触发测试的 java ant 任务/命令行命令不会生成可观察到的副作用,并返回值“13”。 我已经尝试了我能找到的所有方法,并且对 Eclipse 如何启动有了相当多的了解(例如:从 v3.3 开始,您不能再使用startup.jar——它不存在——但您应该使用org.eclipse.equinox。启动器)。 不幸的是,虽然这显然是必要的信息,但还远远不够。
我正在使用 Eclipse 3.4、Junit 4.3.1(org.junit4 包,但我更愿意使用 JUnit 4.4。请参阅此处.)
所以,我的问题是:您究竟如何自动化 Eclipse 插件的构建和测试?
编辑:澄清一下,我想要使用 ant + 巡航控制之类的东西,但我什至根本无法让单元测试运行 > Eclipse 之外。 我说“类似”是因为还有其他技术可以完成同样的事情,并且我不会那么挑剔而放弃仅仅因为它使用 Maven 或 Buckminster 等有效的解决方案,如果这些技术使这变得更加容易的话。
Edit2:上面提到的“Java Result 13”似乎是由于无法找到 coretestrunner 引起的。 从日志中:
java.lang.RuntimeException: Application "org.eclipse.test.coretestapplication" could not be found in the registry. The applications available are: org.eclipse.equinox.app.error, com.rcpquickstart.helloworld.application.
at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:242)
at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
at org.eclipse.core.launcher.Main.main(Main.java:30)
!ENTRY org.eclipse.osgi 2 0 2008-11-04 21:02:10.514
!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:
!SUBENTRY 1 org.eclipse.osgi 2 0 2008-11-04 21:02:10.515
!MESSAGE Bundle update@plugins/org.eclipse.test_3.2.0/ [34] was not resolved.
!SUBENTRY 2 org.eclipse.test 2 0 2008-11-04 21:02:10.516
!MESSAGE Missing required bundle org.apache.ant_0.0.0.
!SUBENTRY 2 org.eclipse.test 2 0 2008-11-04 21:02:10.516
!MESSAGE Missing required bundle org.eclipse.ui.ide.application_0.0.0.
!SUBENTRY 1 org.eclipse.osgi 2 0 2008-11-04 21:02:10.518
!MESSAGE Bundle update@plugins/org.eclipse.ant.optional.junit_3.2.100.jar [60] was not resolved.
!SUBENTRY 2 org.eclipse.ant.optional.junit 2 0 2008-11-04 21:02:10.519
!MESSAGE Missing host org.apache.ant_[1.6.5,2.0.0).
!SUBENTRY 2 org.eclipse.ant.optional.junit 2 0 2008-11-04 21:02:10.519
!MESSAGE Missing required bundle org.eclipse.core.runtime.compatibility_0.0.0.
I am developing Eclipse plugins, and I need to be able to automate the building and execution of the test suite for each plugin. (Using Junit)
Test are working within Eclipse, and I can break the plugins into the actual plugin and a fragment plugin for unit testing as described here, here and in a couple places here.
However, each of the approaches above results in the same issue: The java ant task/commandline command that issues the build or should trigger the test, generates no observable side effects, and returns the value "13". I've tried everything I can find, and I've learned a fair bit about how Eclipse starts up (eg: since v3.3 you can no longer use startup.jar -- it doesn't exist -- but you should use org.eclipse.equinox.launcher). Unfortunately, while that is apparently necessary information, it is far from sufficient.
I am working with Eclipse 3.4, Junit 4.3.1 (the org.junit4 bundle, but I would much rather use JUnit 4.4. See here.)
So, my question is: How exactly do you automate the build and testing of Eclipse plugins?
Edit: To clarify, I want to use something like ant + cruise control, but I can't even get the unit tests to run at all outside of Eclipse. I say "something like" because there are other technologies that accomplish the same thing, and I am not so picky as to discard a solution that works just because it's using say, Maven or Buckminster, if those technologies make this substantially easier.
Edit2: The 'Java Result 13' mentioned above seems to be caused by the inability to find the coretestrunner. From the log:
java.lang.RuntimeException: Application "org.eclipse.test.coretestapplication" could not be found in the registry. The applications available are: org.eclipse.equinox.app.error, com.rcpquickstart.helloworld.application.
at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:242)
at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
at org.eclipse.core.launcher.Main.main(Main.java:30)
!ENTRY org.eclipse.osgi 2 0 2008-11-04 21:02:10.514
!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:
!SUBENTRY 1 org.eclipse.osgi 2 0 2008-11-04 21:02:10.515
!MESSAGE Bundle update@plugins/org.eclipse.test_3.2.0/ [34] was not resolved.
!SUBENTRY 2 org.eclipse.test 2 0 2008-11-04 21:02:10.516
!MESSAGE Missing required bundle org.apache.ant_0.0.0.
!SUBENTRY 2 org.eclipse.test 2 0 2008-11-04 21:02:10.516
!MESSAGE Missing required bundle org.eclipse.ui.ide.application_0.0.0.
!SUBENTRY 1 org.eclipse.osgi 2 0 2008-11-04 21:02:10.518
!MESSAGE Bundle update@plugins/org.eclipse.ant.optional.junit_3.2.100.jar [60] was not resolved.
!SUBENTRY 2 org.eclipse.ant.optional.junit 2 0 2008-11-04 21:02:10.519
!MESSAGE Missing host org.apache.ant_[1.6.5,2.0.0).
!SUBENTRY 2 org.eclipse.ant.optional.junit 2 0 2008-11-04 21:02:10.519
!MESSAGE Missing required bundle org.eclipse.core.runtime.compatibility_0.0.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我刚刚将 JUnit 测试作为 RCP 应用程序无头构建的一部分进行工作。
我找到了这篇文章 - 使用 Ant 自动进行 Eclipse PDE 单元测试< /a> 非常有帮助。 它提供了代码和方法来帮助您入门。 然而,我发现了一些事情:
关于本文的代码,
关于 Eclipse PDE,
uitestapplication
需要另一个testApplication
。 使用 coretestapplication 则不会。我发现提供的代码是一个很好的起点,但在其实现中隐含了许多上述假设。
发现这些假设后,工作就相对简单了。
我们全新的、闪亮的设置
Java Result 13
问题。PDETestListener
我还阅读了插件和功能的构建和测试自动化但我们不直接使用 PDE-Build。
I have just got JUnit testing working as part of the headless build for our RCP application.
I found this article - Automating Eclipse PDE Unit Tests using Ant incredibly helpful. It provides code and approach to get you started. However, a number of things that I discovered:
About the article's code
About Eclipse PDE
uitestapplication
requires anothertestApplication
. Usingcoretestapplication
does not.I found that the code provided was a good starting point, but had a number of the above assumptions implicit in their implementation.
Having discovered these assumptions, doing the work was relatively straight forward.
Our new and shiny setup
Java Result 13
problem.PDETestListener
modified to handle multiple test classesI also read Build and Test Automation for plug-ins and features but we are not using PDE-Build directly.
对于任何仍在寻找一种在 Eclipse 之外执行 Eclipse 插件测试的方法的人,以下命令适合我:
-classpath
应设置为 Eclipse 启动器 jar。 您可以从 eclipse.ini 文件获取 Eclipse 的准确版本。-className
是junit插件测试文件名-data
设置为临时文件。-testpluginname
是您要测试的插件的名称。For any one still looking for a way to execute Eclipse plugin tests outside Eclipse, the following command works for me:
-classpath
should be set to Eclipse launcher jar. You can get exact version for your Eclipse fromeclipse.ini
file.-className
is the junit plugin test file name-data
is set to a temp file.-testpluginname
is the name of plugin you want to test.查看您的异常,它表明 coretestapplication 丢失。 ant 目标可以在plugins/org.eclipse.test_3.1.0/library.xml:10 中找到,
这实际上是一个依赖问题。 Eclipse 需要拥有所有插件才能构建。
要正确配置它,需要查看 2 个文件。
产品
确保产品文件包含您需要的所有插件。
之后,添加 org.eclipse.rcp 和 org.eclipse.test 功能
...
插件在上面
...
您需要 org.eclipse.test 来运行测试,并需要 org.eclipse.rcp 来启动 eclipse 才能运行测试。
不要忘记将 useFeatures 设置为“true”
feature.xml
假设您有一个用于测试的功能,则必须添加 2 个额外的插件。
...
上面的其他插件
...
测试需要 org.apache.ant 来运行测试,并需要 org.eclipse.core.runtime.compatibility 来启动。
另一个问题
确保在您的目标 Eclipse(您用来构建的 Eclipse 副本)中,每个插件只有 1 个副本。 例如,如果插件文件夹中有 2 个版本的 com.ibm.icu 插件,则 eclipse 将使用较新的版本。 由于 pde 构建插件被配置为使用特定版本,eclipse 会抱怨它无法找到特定的插件,即使它在那里。
一些想法
构建 Eclipse 的整个过程还可以更好。 事实上,我主要是通过反复试验才得到这个过程的。 文档已经过时且稀疏。 错误消息没有帮助。 它只会让你感到无助和沮丧。 希望这篇文章可以帮助程序员同行节省一些时间!
Looking at your exception, it says that the coretestapplication is missing. The ant target could be found at plugins/org.eclipse.test_3.1.0/library.xml:10
This is actually a dependency issue. Eclipse needs to have all the plugins in order to build.
To configure it correctly, there're 2 files to look at.
Product
Make sure you the product file contains all the plugins you need.
After that, add the org.eclipse.rcp and org.eclipse.test features
...
plugins are above
...
You need org.eclipse.test to run the tests, and org.eclipse.rcp to launch eclipse in order to run the tests.
Don't forget to set useFeatures to 'true'
feature.xml
Assuming you have a feature for testing, you must add 2 additional plugins.
...
other plugins above
...
THe tests need org.apache.ant to run the tests and org.eclipse.core.runtime.compatibility to launch.
Another gotcha
Ensure that in your target eclipse(the copy of eclipse that you use to build against), there's only 1 copy of each plugin. For example if there're 2 versions of com.ibm.icu plugins in the plugin folder, eclipse would use the newer one. As the pde build plugin is configured to use a specific version, eclipse would complain that it cannot find the particular plugin even when it is there.
Some thoughts
The whole process of building eclipse could be a lot better. In fact I got the process mostly by trial and error. The documentation is outdated and sparse. The error messages doesn't help. It only leaves you feeling helpless and frustrated. Let's hope this post helps a fellow programmer save some time!
我们正在使用 PDE 构建脚本(请参阅这个问题),我们为我们的单元测试插件导出 ant 构建文件。 然后使用“ant”ant 任务从 PDE 构建脚本 (customTargets.xml) 调用这些 ant 构建脚本。 不幸的是,这仅适用于 JUnit3。 应该有一个适用于 JUnit3 的 JUnit4 适配器,以便您可以从 JUnit3 测试运行程序运行 JUnit4 测试。
我们可能会转向像 Maven 这样的东西; PDE 构建脚本并没有真正适合我们需要用它们做的事情。
We're using the PDE build scripts (see this question), and we export ant build files for our unit-test plugins. These ant build scripts are then invoked from the PDE build scripts (customTargets.xml) using the "ant" ant-task. Unfortunately, this only works with JUnit3. There's supposed to be a JUnit4-adapter for JUnit3 so you can run JUnit4 tests from a JUnit3 test-runner.
We'll probably move to something like Maven; the PDE build scripts aren't really cut out for what we need to do with them.
作为 Ant 的替代方案,我在使用全新的 Maven+Tycho 和 Hudson 方面拥有良好的经验。 Tycho 为 Maven 中的 Osgi 和 Eclipse 开发提供完整的支持。 它目前正在大力开发中,但我需要的大部分功能都可以使用。 它只需要您进行很少的配置,因为它可以解析 MANIFEST.MF 文件。
如果您有一些使用 Maven 的经验,那么开始使用它并不难。 Hudson 的问题比较多,因为缺少 Maven 3 支持。 (Tycho使用Maven 3的开发版本)
启动链接:
As an alternative to Ant, I've had good experience in using the brand new Maven+Tycho with Hudson. Tycho provides complete support for Osgi and Eclipse development in Maven. It's currently under heavy development, but most of the features I've needed worked. It needs only very little configuration from your side, because it can parse MANIFEST.MF files.
If you have some experience with Maven it's not very hard to start working with it. Hudson is a bit more problematic because of missing Maven 3 support. (the development version of Maven 3 is used by Tycho)
Links for start:
如果有人对 TDD 感兴趣,我可以推荐以下一个工具:
Infinitest
从 Infinitest 网站提取的简短描述:
Here is a Tool which I can recommand if someone is interrested by TDD :
Infinitest
Short description extracted from the Infinitest site:
使用 Ant 和 CruiseControl - 您在 Ant 脚本以及其余脚本中调用单元测试您的构建逻辑,并可以在每次构建迭代中运行它们 - 然后 CruiseControl 可以自动化您的构建调用并运行这些每次测试。
Use Ant and CruiseControl - you call the unit tests in the Ant script as well as the rest of your build logic and can run them with each build iteration - then CruiseControl can automate your build calls and run these tests each time.