mocha是javascript单元测试框架;平常可以对关键函数进行测试;
安装mocha,断言库chai
全局安装
1) 全局安装mocha好处是:可以在项目中直接使用mocha命令
sudo npm install mocha -g
2) 项目中局部安装断言库chai
sudo npm install chai --save-dev
3) 写好测试用例,可以测试
mocha stu.test.js
局部安装
1) 在项目中局部安装mocha测试框架,chai断言库
sudo npm install mocha chai --save-dev
2) 局部安装如何运行mocha命令呢? 要使用npm run
//package.json "scripts":{ "test":"mocha stu.test.js" //stu.test.js测试文件 }
3) 写好测试用例,执行命令npm run [npm run命令]
sudo npm run test // 执行mocha命令 (npm自动化)
(未完待续)
参考:
[1] 官网
[2] 测试框架mocha