问题描述
我在 Eclipse 中编写了一个自定义启动器,我可以通过类级别的“运行方式”和“调试方式”访问它。我有一个与 How do I use "org.eclipse.debug.ui.launchShortcuts"? 中描述的类似的配置。不幸的是,我无法在方法级别的包资源管理器中看到子菜单(例如,用于启动客户启动器以执行单个 JUnit 测试的子菜单)。我该怎么做?
解决方法
JUnit 使用 contextualLaunch
基于所选元素是 org.eclipse.jdt.core.IJavaElement
而不仅仅是资源。你也需要这样做。
这是 JUnit 使用的:
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.jdt.core.IJavaElement">
<and>
<test property="org.eclipse.jdt.core.isInJavaProject"/>
<or>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="junit.framework.Test"/>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="org.junit.platform.commons.annotation.Testable"/>
</or>
<test property="org.eclipse.jdt.junit.canLaunchAsJUnit" forcePluginActivation="true"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
某些 <test
元素特定于 JUnit,因此您需要使用不同的元素。