Angular 测试用例spec.ts文件批量添加

823 阅读1分钟

背景

在重构代码时候,难免会忘记添加spec.ts测试用例文件,等想起来的时候,已经很多文件了,总不能一个个copy,修改吧,此时正是工具最佳上场时机

angular-spec-generator

通过cli 命令行,为已存在的Angular 文件批量添加测试用例文件

安装

npm install -g angular-spec-generator

支持情况,type选填

typealias
guardg or guard
componentc or component
services or service
directived or directive
pipep or pipe

如何使用

--force ,覆盖已存在的spec文件,添加测试用例会自动根据文件识别

angular-spec-generator 'path to component directory' 

重量级vscode plugin - SimonTest

SimonTest自动根据文件生成对应的测试用例code,只需要人工核对是否正确即可,大大节省人力成本

安装

点击上述链接,vscode安装即可

使用

安装完毕,直接右键点击即可

注意事项

  • 组件需要有Component,Directive等注释
  • 不一定能百分百把测试用例全部自动生成