【问题标题】:JUnitLaunchShortcut with several Class Tests带有多个类测试的 JUnitLaunchShortcut
【发布时间】:2011-11-16 03:46:44
【问题描述】:

当我执行这段代码时:

Object[] segments = new Object[2];
segments[0] = // JUnit Test Class 1
segments[1] = // JUnit Test Class 2

TreePath treepath = new TreePath(segments);
TreeSelection treeselection = new TreeSelection(treepath);

JUnitLaunchShortcut j = new JUnitLaunchShortcut();
j.launch(treeselection, ILaunchManager.RUN_MODE);

Eclipse/JUnit Plugin 只执行JUnit Test Class 2,也许执行了两个Test Class 但只显示在JUnit 查看最后一个Test Class(也许)......

你怎么看?如何“启动”所有测试类?

【问题讨论】:

  • accept回答您之前的问题。
  • 我检查了 JUnitLaunchShortcut 代码并验证了代码转换 TreeSelection 为 IStructuredSelection 并调用 launch(Object[] elements, String mode) ...在整个过程中 ILaunchConfigurationWorkingCopy 只能setAttribute 进行一项测试,但我需要进行 N 次测试... :( 如何创建 ILaunchConfigurationWorkingCopy 来运行多个测试?!或者,如何为 VMArg 添加多个 ILaunchConfigurationWorkingCopy?
  • 经过很多小时,我认为不可能做我想做的事...... Eclipse的RunConfiguration不支持运行我选择的几个测试用例!只运行一个 SingleTestClass 或一个 ProjectPackageSourceFolder,不运行来自多个包的多个测试用例. (我很难过:()

标签: eclipse eclipse-plugin junit


【解决方案1】:

正如您在评论中所说,Eclipse 的 JUnit 插件不支持配置中的多项选择。但是,org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate 确实支持多个测试启动。当您在 JUnit 插件中选择项目/包/测试类并选择作为 JUnit 测试运行时,它会将配置传递给 JUnitLaunchConfigurationDelegate,在那里它会评估要运行的测试。如果有,它会像这样调用 RemoteTestRunner:

RemoteTestRunner -test TestClass

如果它找到多个文件,它会像这样运行:

RemoteTestRunner -testfile testNamesxxxx.txt

其中 testNamesxxx.test 是一个包含要运行的测试列表的文件,例如:

uk.co.farwell.junit.parameters.ParameterTest
uk.co.farwell.junit.run.AllTests
uk.co.farwell.junit.run.Class1Test

此文件是在您的临时目录中创建的。因此,一种可能的探索方法是扩展 JUnitLaunchConfigurationDelegate 并覆盖 evaluateTests 方法,该方法具有如下签名:

protected IMember[] evaluateTests(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {

剩下的就是如何通过 ILaunchConfiguration 传达测试列表,但您也可以为您的插件扩展它。

【讨论】:

  • 这听起来很简单,但它非常困难......很难理解如何扩展 ILaunchConfiguration,我不明白如何添加更多测试,然后调用 RemoteTestRunner...... :(
  • 嗨 Matthew,我扩展了 JUnitLaunchConfigurationDelegate 并像你说的那样覆盖了 evaluateTests 方法......在我创建了一个 ILaunchConfiguration 之后,但是如果我用 Project、Package 或 Class 的 HandleIdentifier 填充 ATTR_TEST_CONTAINER 属性启动器执行在该项目、包或类上呈现的测试,而不是我的覆盖评估返回的测试...如果我不填写该属性,Eclipse 将返回“启动配置的输入类型不存在”。 ..
  • 好的,我再次检查我的代码,我有错误的行 ILaunch launch = wc.launch(ILaunchManager.RUN_MODE, null);我将其更改为 ILaunch launch = new Launch(wc, ILaunchManager.RUN_MODE, null);之后我检查了 testNamesxxxx.txt ,它有我想要的测试名称...... :) 现在问题是 JUnit 没有运行 :( ,什么都没有发生,我认为问题出在 Launch 的创建中。 ..
猜你喜欢
  • 2015-05-22
  • 1970-01-01
  • 2011-10-17
  • 2017-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
相关资源
最近更新 更多