如何使用 angular 8 及更高版本的 SCURI 自动编写单元测试用例

如何使用 angular 8 及更高版本的 SCURI 自动编写单元测试用例

问题描述:

有一个名为 SCURI 的 npm 包,可用于自动为 .ts 文件编写单元测试用例以覆盖超过 70% 的覆盖率.

There is an npm package named SCURI which can be utilized to write unit test cases for .ts files automatically to cover more than 70% coverage .

只需要安装这个包,一旦完成,创建 autoSpy.ts 文件来定义如何模拟/创建依赖项的存根.

Just need to install this package and once done, create autoSpy.ts file to define how to mock/create stubs for dependencies.

正如文档中所述,它

自动化 Angular 的单元测试样板

Automates unit test boilerplate for Angular

因此,减少了无脑操作,即规范文件创建、导入、构造函数实例化、方法调用、基本 AAA 模式、一些模拟等.

so, reduces the no-brainers, i.e spec file creation, imports, constructor instantiations, method invocations, basic AAA pattern, some mocking etc.

所有(高级)逻辑设计和检查你最好自己做.

All the (advanced) logical design and checks you better do yourself.