测试插件-infinitest介绍

缘起

写多了业务代码,一些遗留系统里处于基本没有单测的状态,所以最近对 TDD 的开发方式很感兴趣,看了很多 TDD 介绍和实践的书。git

TDD 对测试的执行次数有很高的要求,可是日常在 idea 里面写代码运行测试所需时间较长,须要先 build 才能启动测试,这就成了咱们践行 TDD 的障碍,咱们须要一款对测试友好的插件来帮助咱们。github

infinitest 插件可让咱们免除手动执行测试的尴尬,它检测文件的 class 变更,当文件有变更时,能够自动执行测试,开箱即用。infinitest 也可使用简单的配置,让咱们把 infinitest 和 Junit 相关特性结合起来,更显方便正则表达式

安装与使用

安装很简单:框架

Settings -> Plugins -> Browse repositories -> 查找infinitest -> Install -> Restart ideaide

添加到项目中:测试

Project Structure(ctrl+shift+alt+s) -> Modules -> 添加infinitestui

idea 默认不会自动 compile文件,咱们须要开启一下idea

Settings -> Build, Execution, Deployment -> Compiler -> Build project automatically 打上勾插件

若是项目中只有简单的测试,这样就能够了,若是咱们须要区分不一样的测试,咱们须要本身添加文件来配置一下。code

配置

总的文档目录 infinitest docs

filters

这个配置可让咱们指定须要执行哪些测试,不执行哪些测试,支持 Junit4 的 category 和 Junit5 的 tags

  • 添加配置文件

本身新建一个infinitest.filters, 将文件放在.iml同级目录下便可。

  • 经过 class name,支持正则表达式
# Include tests that end in ITest or TestCase
include .*ITest, .*TestCase

# Exclude Inner Classes
exclude .*\$.*

# Include tests in package com.mycompany.mypackage and sub-packages
include com\.mycompany\.mypackage\..*

# Include tests in package com.mycompany.mypackage and not in sub-packages
include com\.mycompany\.mypackage\.[^.]*
  • 经过 Junit5 的 tags
# Include tests with "Fast" and "Regression" tags
includeGroups Fast, Regression

# Exclude tests with "Slow" tag
excludeGroups Slow
  • 经过 Junit4 的 category
# Include tests in FastTests and RegressionTests categories
includeGroups com.example.FastTests, com.example.RegressionTests

# Exclude SlowTests category
excludeGroups com.example.SlowTests

testNg 框架相关的不作介绍,具体能够参见 infinitest filters

JVM options

新建infinitest.args文件,位置与filters的同样,里面每一行是一个虚拟机参数,这个配置会覆盖 infinitest 的默认配置

最后

你们若是遇到什么问题能够先 Google 一下,若是没有找到答案,能够在 GitHub 上自行提问。

相关文章
相关标签/搜索