测试插件-infinitest介绍
时间: 2018-08-11来源:OSCHINA
前景提要
缘起
写多了业务代码,一些遗留系统里处于基本没有单测的状态,因此最近对 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 上自行提问。

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行