开发单元测试脚手架 - 第二篇 - 插件扩展点
单元测试脚手架在plugin.xml中的配置如下:
?
<!--amt operation--><extension point="org.eclipse.ui.popupMenus"> <!--定义对象操作,上下文菜单--> <!--nameFilter="*DAO*.java,*Service*.java"--> <objectContributionadaptable="false"id="org.jtester.amt.type.popuMenutContribution"objectClass="org.eclipse.jdt.core.IType"> <action class="org.jtester.amt.actions.MakeToTestFromTypeAction" icon="icons/amtLogo.gif" id="org.jtester.amt.type.makeToTest" label="make to test" menubarPath="additions"> </action> </objectContribution> <objectContributionadaptable="false"id="org.jtester.amt.compilationunit.popuMenutContribution"objectClass="org.eclipse.jdt.core.ICompilationUnit"> <action class="org.jtester.amt.actions.MakeToTestFromCompilationUnitAction" icon="icons/amtLogo.gif" id="org.jtester.amt.compilationunit.makeToTest" label="make to test" menubarPath="additions"> </action> </objectContribution> <!--定义*.java编辑器上下文菜单--> <viewerContributionid="org.jtester.amt.viewerContribution"targetID="#CompilationUnitEditorContext"> <action class="org.jtester.amt.actions.MakeToTestEditorAction" definitionId="org.jtester.amt.command.makeToTest" icon="icons/amtLogo.gif" id="org.jtester.amt.editor.makeToTest" label="make to test" menubarPath="additions"> </action> </viewerContribution></extension><!--定义amt command--><extension point="org.eclipse.ui.commands"> <categoryid="org.jtester.amt.category.makeToTest"name="amt"> </category> <commandcategoryId="org.jtester.amt.category.makeToTest"id="org.jtester.amt.command.makeToTest"defaultHandler="org.jtester.amt.handler.MakeToTestActionHandler"name="make to test"> </command></extension><!--amt command binding.--><extension point="org.eclipse.ui.bindings"> <key sequence="CTRL+SHIFT+ALT+M" commandId="org.jtester.amt.command.makeToTest" contextId="org.eclipse.jdt.ui.javaEditorScope" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"></key></extension>?
这里提供了这么几个特性:
1、Package Explorer、Java Editor中能够以右键菜单的方式选取“make to test”选项来打开生成单元测试代码的导航窗口;
2、另外在编辑器中,可以通过组合快捷键 CTRL+SHIFT+ALT+M来打开导航窗口。
?
(TODO:因为界面部分代码并非笔者开发的,所以还需要熟悉之后,再补充详细说明。)
?