测试插件-infinitest介绍

缘起

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

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

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

安装与使用

安装很简单:

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

添加到项目中:

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

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

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

如果项目中只有简单的测试,这样就可以了,如果我们需要区分不同的测试,我们需要自己添加文件来配置一下。

配置

总的文档目录 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 上自行提问。

转载于:https://my.oschina.net/liufq/blog/1926365

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值