Skip to main content

保存的帖子

连续单元检查:
Part Three

阅读: 连续单元检查:第三部分

Continuous Unit Checking

Where were we?

  • 第1部分:命令行实用程序和包装脚本
  • 第2部分: Guard (with Ruby) and SBT (with Scala)
  • 第3部分(this):Infinitest(带有Java和Intellij Idea)

在第1部分中,我们研究了一些基于Shell命令和包装脚本的简单连续检查解决方案。在第2部分中,我们稍微爬上了一堆工具,并尝试了防护(Ruby)和SBT(Scala)。现在我们会看看Infinitestfor Java, with JetBrains IntelliJ IDEA.

Infinitest was one of two continuous checking tools for Java that came out in the early 2000s; the other was Kent Beck’s JUnitMax. Both products were initially offered on a paid basis, but the market was not ready to pay for continuous checking at the time. JUnitMax was withdrawn, and Infinitest converted to a “free” distribution model.

综合开发环境

一些开发人员更喜欢command-line-centric产品开发lopment work flow, while others prefer an integrated development environment (IDE) that presents a suite of development tools within a single application window. IDEs always include a text editor; usually one that has some language-aware features such as syntax highlighting, autocompletion, and (possibly) intellisense. Another handy feature of modern editors (both standalone and embedded in IDEs) is the ability to define snippets of code for boilerplate functionality and drop them into your application in a more-or-less intelligent way.

In most cases, support for one or more unit testing frameworks is either bundled with the IDE or is available as a plugin. IDEs often include a debugger and a profiler, as well. Assisted refactoring is another feature that has become a basic expectation in any high-end IDE.

最后,大多数IDE提供了执行外部工具并管理它们而不离开IDE的某种方法。这些可以包括版本控制系统,DIFF实用程序,服务器,Web浏览器,无线设备模拟器,依赖性管理器和构建实用程序。

IDE的优点之一是产品连接各种工具,以便您可以轻松地导航,例如,在违规的代码线上或直接从特定代码行中直接与文本编辑器进行导航当时进入调试器。使用命令行上的独立工具,您将无法获得集成水平。

这将是一个很好的一天,对连续单位检查成为IDE的预期基线功能的支持。在此之前,Java开发人员比其他人享有优势,因为可以使用该无限端。

在Intellij Idea中安装Infinitest

Infinitest was originally written as an IntelliJ IDEA plugin, and was later ported to Eclipse. As of today I’m not sure how the Infinitest team handles development, but it seems as if IntelliJ IDEA still gets preference. To get the latest functionality and (probably) the best support, I suggest using Infinitest with IntelliJ IDEA.

To install Infinitest, open the Preferences or Settings dialog in IntelliJ IDEA. You can do this with a keyboard shortcut (by default it’s “⌘,” on OSX and “Ctrl+Alt+S” on Windows or Linux) or by opening Preferences from the main menu bar (under “IntelliJ IDEA => Preferences” on OSX and under “File => Settings” on Windows and Linux).

在“首选项或设置”对话框中,选择“插件”选项卡(在面板的左侧选择)。在面板顶部附近的搜索框中,键入“ Infinitest”。如果尚未安装Infinitest,Intellij将邀请您安装它。单击“安装”按钮继续进行。

下载必要的组件后,Intellij将通知您重新启动它。

安装了无限端。为了在项目中使用它,您必须在该项目上启用最无限的方面。首先,让我们创建一个微不足道的项目。

Incrementer Project

为了锻炼不利士,我创建了一个琐碎的项目,称为incrementer与本系列第1部分和第2部分中定义的Python,Ruby和Scala项目相同。这是“应用程序”代码:

公共类增量器{public int增量(int number){返回号码 + 1;}}}

and here’s the “unit test suite”:

import org.junit.Test; import static org.junit.Assert.assertEquals; public class IncrementerTest { @Test public void increment_returns_3_when_original_value_is_2() { assertEquals(3, new Incrementer().increment(2)); } }

Enabling Infinitest

Infinitest is installed, but it doesn’t “just work.” To make use of it in a project, you have to enable the Infinitest facet on that project. (Remember that as we climb the pile of tools, configuration becomes more tedious. That’s the price of admission for additional functionality.)

Open the project settings forincrementer。在OSX上,您可以使用键盘快捷键“ - ”;或菜单选项“文件=>项目结构”。在Windows或Linux上,使用键盘快捷键“ Ctrl+Alt+Shift+S”或菜单选项“文件=>项目结构”。

选择“ facets”(面板左侧的选项)。单击加号(+)添加一个刻度。向下滚动到无限端。这使您达到这一点:

出现“选择模块”弹出窗口。

Choose “incrementer_test”.

Now Infinitest is enabled for the incrementer_test module of project incrementer. But it still won’t work. You have to set the “Make project automatically” option.

只是为了娱乐,围绕此的文档非常令人困惑。您会看到对“项目设置”的引用,但意味着“ IDE设置”或“偏好”。您要寻找的设置是not在项目级别。打开首选项或洞穴ings dialog as you did before.

现在选择“编译器”。您可以在左侧或右侧的入口选择。他们导致同一地方:

Look for the checkbox labeled “Build project automatically” and select it:

To see the test results, you have select “View => Tool Windows =>modulename” from the main menu.

At this point, Infinitest will watch for changes in the module and run the relevant unit checks whenever a change is detected. It detects changes when a file is saved. Note that IntelliJ saves periodically in the background, so Infinitest may report test results even if you haven’t explicitly saved.

这是一个简短的演示:

Conclusion

在这一系列帖子中,我们简要介绍了连续单元检查的几个选项。主要的外卖是,让我们的工具照顾在后台运行我们的单元检查,以使我们释放我们的“前景”思维,以解决我们试图解决的问题。

对于开发的其他方面,没有那么多的工具来支持这一点,但是我们确实有几种选择。它们跨越从简单但犯罪feature-rich-and-complicated

Both the typical preferences for development work flow are accommodated: Separate tools running in their own terminals (for any language), or integrated tools bundled within an IDE (for Java and other JVM languages, anyway).

下一个敏捷医院

发表评论

Your email address will not be published. Required fields are marked*