在 Eclipse 插件中测试自动完成

Testing autocompletion in an Eclipse plugin

我正在开发一个 Eclipse 插件,它提供 属性 自动完成功能,其中 ICompletionProposalComputer 通过 org.eclipse.wst.sse.ui.completionProposal 贡献。

我想为功能创建自动化测试,但不知道从哪里开始。如何为我的提案计算机编写自动化测试?

前段时间我和一位同事在为 SourceViewer based editor in a console view.

实现 IContentAssistProcessor 时遇到了类似的问题

我们从一个集成测试开始,该测试模拟控制台编辑器中的 Ctrl+Space 击键,并期望 shell 和 table 持有要显示的提案。

下面是这样一个测试用例:ConsoleContentAssistPDETest. It uses a ConsoleBot that encapusulates the key stroke simulation and a custom AssertJ assertion that hides the details of waiting for the shell to open and finding the table, etc. (ConsoleAssert)

通过这样的测试,我们能够 implement a walking skeleton。我们通过单元测试开发了测试驱动的内容提案代码的各个部分。

除了编写自己的 bot,您还可以查看 SWTBot,它提供了 API 来编写 UI/functional 测试。

我最终写了一个简单的 SWTBot 测试。打开编辑器后,获取自动完成列表非常简单:

bot.editorByTitle("index.html").toTextEditor();
editor.insertText("<html>\n<div  ></div>\n</html>");
editor.navigateTo(1, 5);
editor.getAutoCompleteProposals("")