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

rcr*_*ick 16 java testing junit eclipse-pde eclipse-3.4

我正在开发Eclipse插件,我需要能够为每个插件自动构建和执行测试套件.(使用Junit)

测试是在Eclipse中工作,并按照上述方法我可以打破插件到实际的插件和片段插件单元测试在这里,这里和在几个地方在这里.

但是,上述每种方法都会导致相同的问题:发出构建或应触发测试的java ant task/commandline命令,不会产生可观察到的副作用,并返回值"13".我已经尝试了所有我能找到的东西,并且我已经了解了Eclipse如何启动(例如:从v3.3开始,你不能再使用startup.jar - 它不存在 - 但你应该使用org.eclipse.equinox.launcher).不幸的是,虽然这显然是必要的信息,但远远不够.

我正在使用Eclipse 3.4,Junit 4.3.1(org.junit4包,但我更喜欢使用JUnit 4.4.请看这里.)

所以,我的问题是:你如何自动化Eclipse插件的构建和测试?

编辑:为了澄清,我使用像ant +巡航控制这样的东西,但我甚至无法让单元测试 Eclipse之外运行.我说"类似的东西",因为有其他技术可以实现同样的目标,而且我不会那么挑剔,因为它丢弃了一个解决方案,只是因为它使用了say,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.
Run Code Online (Sandbox Code Playgroud)

jam*_*esh 12

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

我发现这篇文章 - 使用Ant自动化Eclipse PDE单元测试非常有帮助.它提供了帮助您入门的代码和方法.但是,我发现了很多东西:

关于文章的代码

  • 测试中只有一个包(我们已经使用Buckminster从代码中分离出我们的构建过程)
  • 只有一个测试类.
  • 这些都被有效地硬编码到构建脚本中

关于Eclipse PDE

  • uitestapplication需要另一个testApplication.使用coretestapplication没有.
  • 因为这些应用程序都是捆绑在一起,依赖于SWT.在大多数情况下,这是一个交易杀手,但如果您的构建计算机是Windows机箱,则不是这样.我很乐意看到这些分为非UI捆绑.

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

在发现这些假设之后,做这项工作相对简单.

我们新的闪亮设置

  • buckminster构建捆绑包.
  • target将目标平台上的bundle,org.eclipse.pde.runtime和org.eclipse.jdt.junit复制到"tester-eclipse-install"中.这应该照顾你的Java Result 13问题.
  • 通过查看工作区找到测试片段
  • 通过查看清单找到片段主机
  • 通过查看工作区中的项目来查找测试类.
  • 注册一个PDETestListener修改后的处理多个测试类
  • 使用多个测试类调用tester-eclipse-install.

我还阅读了构建和测试自动化的插件和功能,但我们没有直接使用PDE-Build.


Jes*_*erE 0

我们正在使用 PDE 构建脚本(请参阅此问题),并为我们的单元测试插件导出 ant 构建文件。然后使用“ant”ant 任务从 PDE 构建脚本 (customTargets.xml) 调用这些 ant 构建脚本。不幸的是,这仅适用于 JUnit3。应该有一个适用于 JUnit3 的 JUnit4 适配器,以便您可以从 JUnit3 测试运行程序运行 JUnit4 测试。

我们可能会转向像 Maven 这样的东西;PDE 构建脚本并没有真正适合我们需要用它们做的事情。