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

标签 java testing junit eclipse-pde eclipse-3.4

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

测试在 Eclipse 中工作,我可以将插件分解为实际插件和用于单元测试的片段插件,如所述 here , here在几个地方here .

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

我正在使用 Eclipse 3.4、Junit 4.3.1(org.junit4 包,但我更愿意使用 JUnit 4.4。请参阅 here。)

所以,我的问题是:您究竟如何自动化 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.

最佳答案

我刚刚将 JUnit 测试作为我们 RCP 应用程序 headless 构建的一部分。

我找到这篇文章 - Automating Eclipse PDE Unit Tests using Ant非常有帮助。它提供了代码和方法来帮助您入门。但是,我发现了一些事情:

关于文章的代码

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

关于 Eclipse PDE

  • uitestapplication 需要另一个 testApplication。使用 coretestapplication 不会。
  • 因为这些应用程序都在依赖于 SWT 的 bundle 中。在大多数情况下,这是一个交易 killer ,但如果您的构建机器是 Windows 机器则不会。我很乐意看到这些拆分成非 UI 包。

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

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

我们崭新而 Shiny 的设置

  • buckminster 构建 bundle 。
  • target 将来自目标平台的包、org.eclipse.pde.runtime 和 org.eclipse.jdt.junit 复制到“tester-eclipse-install”中。这应该可以解决您的 Java Result 13 问题。
  • 通过查看工作区找到测试片段
  • 通过查看 list 找到片段宿主
  • 通过查看工作区中的项目找到测试类。
  • 注册一个修改过的PDETestListener来处理多个测试类
  • 使用多个测试类调用 tester-eclipse-install。

我还读了Build and Test Automation for plug-ins and features但我们没有直接使用 PDE-Build。

关于java - 用于 Eclipse 插件开发的自动化单元测试 (junit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/255370/

相关文章:

java - Android 目标 fragment 未出现在导航上

java - 如何从父引用调用子方法?

perl - 在 Perl 中写入文件时测试错误处理的最简单方法是什么?

java - 单独运行 JUnit 测试*方法*

android - Gradle Wrapper 4.6 无法识别测试过滤参数

java - 是否有任何适用于 Java 的假文件系统框架?

java - 修改 JTable 单元格中的文本对齐方式

javascript - 将具有换行符的文本与另一个字符串匹配

python - 测试 Django 时仅针对特定版本显示弃用警告

java - 连接到数据库的 Rest API 的 Junit 测试用例