首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从其他Eclipse插件调用JUnit

问从其他Eclipse插件调用JUnit
EN

Stack Overflow用户
提问于 2011-11-09 19:19:35
回答 2查看 1.5K关注 0票数 1

我正在为Eclipse进行开发,其中一个功能是运行JUnit测试。现在我的插件在工作区中的一个项目上检测JUnit测试,然后我想调用JUnit来运行这个测试。

我听说过ILaunch,ILaunchConfigurationDelegate,JUnitLaunchConfigurationDelegate,但我找不到一个这样的例子,而且我也不确定我是否必须使用这个!

--提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-09 20:17:46

请看我对How does Eclipse actually run Junit tests?的回答。您将需要创建一个运行配置,然后使用该配置调用JUnitLaunchConfigurationDelegate#launch()。

最简单的方法是向扩展点org.eclipse.debug.ui.launchShortcuts添加快捷方式。有了正确的configurationType,您就可以创建正确的类型,正常情况下,Eclipse将完成剩下的工作。事实上,这正是我们在Scala IDE中所做的。

下面是scala-ide中的相关XML:

代码语言:javascript
复制
<extension point="org.eclipse.debug.ui.launchShortcuts">
    <shortcut
          label="%JUnitShortcut.label"
          icon="$nl$/icons/full/obj16/julaunch.gif"
          helpContextId="org.eclipse.jdt.junit.launch_shortcut"
          class="org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut"
          modes="run, debug"
          id="scala.tools.eclipse.scalatest.junitShortcut">
       <contextualLaunch>
          <enablement>
             <with variable="selection">
                <count value="1"/>
                <iterate>
                   <adapt type="org.eclipse.jdt.core.IJavaElement">
                      <test property="org.eclipse.debug.ui.matchesPattern" value="*.scala"/>
                      <test property="org.eclipse.jdt.core.isInJavaProject"/>
                      <test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="junit.framework.Test"/>
                      <or>
                      <test property="scala.tools.eclipse.launching.canLaunchAsJUnit" forcePluginActivation="true"/>
                      <test property="scala.tools.eclipse.launching.junit.canLaunchAsJUnit" forcePluginActivation="true"/>
                      </or>
                   </adapt>
                </iterate>
             </with>
          </enablement>
       </contextualLaunch>
       <configurationType
             id="org.eclipse.jdt.junit.launchconfig">
       </configurationType>
       <description
             description="%DebugJUnitLaunchShortcut.description"
             mode="debug">
       </description>
       <description
             description="%RunJUnitLaunchShortcut.description"
             mode="run">
       </description>
    </shortcut>
</extension>

重要的元素是,它定义了一组测试,为了将以JUnit身份启动的选项呈现给用户,这些测试必须为真。其中大多数都是自解释的,但我们也有引用扩展点org.eclipse.core.expressions.propertyTesters的scala.tools.eclipse.launching.canLaunchAsJUnit。这些属性测试器测试代码是否可以作为JUnit启动(例如,被测试的类是否扩展了TestCase或其他什么)。

如果你需要更多细节,我建议下载Scala IDE,并查看代码,但它是用Scala编写的。

票数 2
EN

Stack Overflow用户

发布于 2014-06-10 11:41:08

我重写了部分启动junit服务,然后通知项目它调用了debug并运行。

请参阅我的实现以调用JUnitLaunch

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8064249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档