Our Eclipse-based product plugs into the platform debug support. And we have a
large number of launch shortcuts which have enablement expressions specified in
plugin.xml. And they are a huge pain in the ass to test manually. If a
particular shortcut is disabled when it should be enabled, there isn't a good
way (that I've seen) to trace the evaluation of the enablement expression at
runtime. So it comes down to stepping through the deeply nested
Expression.evaluate(..) calls, and you can easily get lost.
This is one of those times where I feel
like the light bulb should have gone on for me years ago. It turns out there is
a much easier way to test these things: by writing JUnit Plug-in Tests for
them.
What follows is some sample code to do
this. Since I'm testing the enablement of launch shortcuts, the configuration
elements are specific to that scenario, but you should be able to do this for
any expression that appears in a bundle's plugin.xml.
In
a @Before method, I read the expression from the plugin.xml and convert it into
an Expression object.
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.EXTENSION_POINT_LAUNCH_SHORTCUTS);
IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
for (IConfigurationElement elem : infos) {
String id = elem.getAttribute("id");
IConfigurationElement contextLaunch = null;
IConfigurationElement enablement = null;
if ("myShortcutId".equals(id)) {
contextLaunch = elem.getChildren("contextualLaunch")[0];
enablement = contextLaunch.getChildren("enablement")[0];
expression = ExpressionConverter.getDefault().perform(enablement);
}
And in a @Test method, I set up the context
I'm trying to mimic and evaluate the expression.
@Test
public void ui() throws Exception {
List<object> ctxt = new ArrayList<object>();
ctxt.add(selectedObject /*Some IResource, perhaps*/);
IEvaluationContext context = new EvaluationContext(null, ctxt);
context.addVariable("selection", ctxt); //$NON-NLS-1$
assertEquals(EvaluationResult.valueOf(m_uiEnabled), expression.evaluate(context));
}
Now I can muck around in those delicately
constructed XML expressions and rest assured that I have a test suite watching
my back.
分享到:
相关推荐
declarative services
Pure Declarative Programming in Swift, Among Other Things.zip,swift中的纯声明式编程
Declarative dependency management for Matlab.zip
<declarative> 自定义元素以声明方式创建Shadow DOM 它应该与给出的建议紧密合作演示版安装使用安装组件:$ bower install declarative-shadow-dom --save 或 。用法如果需要,内置的导入自定义元素可扩展polyfill&...
1.Declarative Inspector检查选定的DOM元素的声明性视图模型属性(动作,ctx,数据,dataProvider,i18n,消息,onEvent)。 请参见声明性检查器示例的屏幕截图。 2.Declarative Tracer跟踪关键声明事件的执行流程...
Why is GraphQL the most innovative technology for fetching data since Ajax? By providing a query language for your APIs and a runtime for fulfilling queries with your data, GraphQL presents a clear ...
Qt5Declarative_jll.jl (v5.15.2 + 0) 这是使用构造的自动生成的包。 原始的脚本可以在社区构建树上找到。 如果您有任何问题,请向Yggdrasil报告。 有关JLL软件包以及如何使用它们的更多详细信息,请参见...
declarative-parser.zip,将bean定义组成正则表达式的解析器,用于
主要介绍了python SQLAlchemy的Mapping与Declarative详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
python库。 资源全名:wavestate.declarative-1.3.4.tar.gz
它使用作为辅助库,其思想源于以及Kevlin Henney关于的精彩演讲怎么跑git clone https://github.com/dbagia/declarative-demos.git yarn yarn test文献资料演示下的每个文件夹都有其自己的自述文件,以解释问题,...
jquery-declarative 与每个 jQuery 插件一起工作,而无需使用任何额外的 javascript。 在 jQuery 中,您可以使用类似的方法将控件分配给 HTML 元素: $ ( document ) . ready ( function ( ) { $ ( '#portfoio'...
资源来自pypi官网。 资源全名:django_declarative_apis-0.19.0-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:aiogram_declarative-0.1.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Swift声明式配置 Swift声明式配置(简称SDC)是一个很小的库,使您能够以符合人体工程学的方式以声明式,一致且易于理解的方式配置对象。 它可用于配置任何平台上的任何对象,包括服务器端swift。...
geomajas-project-sld-editor.zip,专家级sld编辑器gwt示例应用程序代码geomajas sld编辑器项目