用于 Eclipse 插件开发的自动化单元测试 (junit)

发布于 2024-07-08 02:00:02 字数 3749 浏览 6 评论 0原文

我正在开发 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

傲娇萝莉攻 2024-07-15 02:00:02

我刚刚将 JUnit 测试作为 RCP 应用程序无头构建的一部分进行工作。

我找到了这篇文章 - 使用 Ant 自动进行 Eclipse PDE 单元测试< /a> 非常有帮助。 它提供了代码和方法来帮助您入门。 然而,我发现了一些事情:

关于本文的代码,

  • 只有一个包正在测试中(我们已经将构建过程与代码分开,使用 Buckminster)
  • 只有一门测试课。
  • 这些都被有效地硬编码到构建脚本中。

关于 Eclipse PDE,

  • uitestapplication 需要另一个 testApplication。 使用 coretestapplication 则不会。
  • 因为这些应用程序都位于依赖于 SWT 的捆绑包中。 在大多数情况下,这是一个交易杀手,但如果您的构建机器是 Windows 机器则不然。 我希望看到这些被分成非 UI 包。

我发现提供的代码是一个很好的起点,但在其实现中隐含了许多上述假设。

发现这些假设后,工作就相对简单了。

我们全新的、闪亮的设置

  • 巴克明斯特构建了捆绑包。
  • target 将包从目标平台、org.eclipse.pde.runtime 和 org.eclipse.jdt.junit 复制到“tester-eclipse-install”中。 这应该可以解决您的 Java Result 13 问题。
  • 通过查看工作区找到测试片段通过查看
  • 清单找到片段主机通过查看
  • 工作区中的项目找到测试类。
  • 注册一个修改为处理多个测试类的 PDETestListener
  • 调用具有多个测试类的 tester-eclipse-install。

我还阅读了插件和功能的构建和测试自动化但我们不直接使用 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

  • there was only one bundle under tests (we have separated out our build process from the code, using Buckminster)
  • there was only one test class.
  • these were both effectively hardcoded into the build script

About Eclipse PDE

  • the uitestapplication requires another testApplication. Using coretestapplication does not.
  • as these applications are both in bundles that have dependencies on SWT. This is a deal killer in most circumstances, though not if your build machine is a Windows box. I would love to see these split into non-UI bundles.

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

  • buckminster builds the bundles.
  • target copies the bundles from the target platform, the org.eclipse.pde.runtime and org.eclipse.jdt.junit into a "tester-eclipse-install". This should take care of your Java Result 13 problem.
  • find the test fragments from looking at the workspace
  • find the fragment host from looking at the manifest
  • find the test classes from looking at the project in the workspace.
  • register a PDETestListener modified to handle multiple test classes
  • invoke the tester-eclipse-install with the multiple test classes.

I also read Build and Test Automation for plug-ins and features but we are not using PDE-Build directly.

北城半夏 2024-07-15 02:00:02

对于任何仍在寻找一种在 Eclipse 之外执行 Eclipse 插件测试的方法的人,以下命令适合我:

java -Xms40m -Xmx1024m -XX:MaxPermSize=512m -Dorg.eclipse.swt.browser.DefaultType=mozilla -Declipse.pde.launch=true -classpath C:\eclipse\eclipse-standard-luna-M2-win32-x86_64\eclipse\plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar org.eclipse.equinox.launcher.Main -port 22 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames testpackage.testClass -application org.eclipse.pde.junit.runtime.uitestapplication -data C:\temp\log.temp -dev bin -consoleLog -testpluginname PluginName

-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:

java -Xms40m -Xmx1024m -XX:MaxPermSize=512m -Dorg.eclipse.swt.browser.DefaultType=mozilla -Declipse.pde.launch=true -classpath C:\eclipse\eclipse-standard-luna-M2-win32-x86_64\eclipse\plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar org.eclipse.equinox.launcher.Main -port 22 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames testpackage.testClass -application org.eclipse.pde.junit.runtime.uitestapplication -data C:\temp\log.temp -dev bin -consoleLog -testpluginname PluginName

-classpath should be set to Eclipse launcher jar. You can get exact version for your Eclipse from eclipse.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.

姜生凉生 2024-07-15 02:00:02

查看您的异常,它表明 coretestapplication 丢失。 ant 目标可以在plugins/org.eclipse.test_3.1.0/library.xml:10 中找到,

这实际上是一个依赖问题。 Eclipse 需要拥有所有插件才能构建。

要正确配置它,需要查看 2 个文件。

  1. 产品文件
  2. feature.xml

产品

确保产品文件包含您需要的所有插件。

之后,添加 org.eclipse.rcp 和 org.eclipse.test 功能

...
插件在上面
...

<features>
      <feature id="mock_feature" version="1.0.0"/>
      <feature id="mock_feature_test" version="1.0.0"/>
      <feature id="org.eclipse.rcp" version="3.2.0.v20060609m-SVDNgVrNoh-MeGG"/>
      <feature id="org.eclipse.test" version="3.2.0.v20060220------0842282442"/>
 </features>

您需要 org.eclipse.test 来运行测试,并需要 org.eclipse.rcp 来启动 eclipse 才能运行测试。

不要忘记将 useFeatures 设置为“true”

<product name="mock" id="com.example.mock" application="com.example.mock.application" useFeatures="true">

feature.xml

假设您有一个用于测试的功能,则必须添加 2 个额外的插件。

...
上面的其他插件
...

<plugin
         id="org.apache.ant"
         download-size="0"
         install-size="0"
         version="0.0.0"/>

   <plugin
         id="org.eclipse.core.runtime.compatibility"
         download-size="0"
         install-size="0"
         version="0.0.0"
         unpack="false"/>

测试需要 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.

  1. The product file
  2. The feature.xml

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
...

<features>
      <feature id="mock_feature" version="1.0.0"/>
      <feature id="mock_feature_test" version="1.0.0"/>
      <feature id="org.eclipse.rcp" version="3.2.0.v20060609m-SVDNgVrNoh-MeGG"/>
      <feature id="org.eclipse.test" version="3.2.0.v20060220------0842282442"/>
 </features>

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'

<product name="mock" id="com.example.mock" application="com.example.mock.application" useFeatures="true">

feature.xml

Assuming you have a feature for testing, you must add 2 additional plugins.

...
other plugins above
...

<plugin
         id="org.apache.ant"
         download-size="0"
         install-size="0"
         version="0.0.0"/>

   <plugin
         id="org.eclipse.core.runtime.compatibility"
         download-size="0"
         install-size="0"
         version="0.0.0"
         unpack="false"/>

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!

月下客 2024-07-15 02:00:02

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.

溺孤伤于心 2024-07-15 02:00:02

作为 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:

月依秋水 2024-07-15 02:00:02

如果有人对 TDD 感兴趣,我可以推荐以下一个工具:
Infinitest

从 Infinitest 网站提取的简短描述:

什么是无限测试?

Infinitest 是一个连续测试运行程序
旨在促进测试驱动
发展。 无限极帮您
通过提供反馈来学习 TDD
工作,并帮助您掌握 TDD
缩短您的反馈周期
分钟到几秒。

每当你改变班级时,
Infinitest 为您运行测试。
运行哪些测试是明智的,
并且只运行您需要的那些。 如果
发生任何错误,它都会报告它们
清晰简洁。 这给你
关于语义的即时反馈
您的代码的正确性,就像
现代 IDE 为您提供即时反馈
关于语法错误。

Here is a Tool which I can recommand if someone is interrested by TDD :
Infinitest

Short description extracted from the Infinitest site:

What is Infinitest?

Infinitest is a continuous test runner
designed to facilitate Test Driven
Development. Infinitest helps you
learn TDD by providing feedback as you
work, and helps you master TDD by
reducing your feedback cycle from
minutes to mere seconds.

Whenever you change a class,
Infinitest runs your tests for you.
It's smart about what tests to run,
and only runs the ones you need. If
any errors occur, it reports them
clearly and concisely. This gives you
instant feedback about the semantic
correctness of your code, just as
modern IDE's give you instant feedback
about syntax errors.

你在我安 2024-07-15 02:00:02

使用 AntCruiseControl - 您在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文