【发布时间】:2022-01-07 10:33:44
【问题描述】:
我正在使用 mocha 为我的节点 js 应用程序运行单元测试。 我使用以下命令运行测试用例。
npm run mocha test/controller
test/controller 是测试类包。
以下是单元测试的示例代码。
const controller = require(./controller);
describe("execute", =>{
sinon.stub().restore();
const req= {name:"tina", dob:"2-12-2000"};
it("call method to post" =>{
const res = controller.result();
//test fails in the below line
sinon.assert(axios.post,"http://dummyurl/login,req);
});
});
当执行测试用例时,它只显示通过的测试数量,而不是覆盖率报告,如下表所示。
✓ call method to post
1 passing (5ms)
---------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files | 58.33 | 50 | 50 | 58.33 |
Producer.js | 33.33 | 100 | 0 | 33.33 | 7-17
controller.js | 100 | 50 | 100 | 100 | 6
---------------|---------|----------|---
有人可以帮忙吗? 提前非常感谢。
【问题讨论】:
-
JUnit 是一个 Java 测试工具。您是否进行了任何配置以尝试获得覆盖?
-
我没有添加任何配置来获得覆盖。我使用 mocha 来运行测试用例。如果这部分有遗漏,您能否详细说明一下?
-
是的,你错过了......任何获得覆盖的配置!我建议围绕可用的覆盖工具以及如何将其集成到您的测试中进行一些研究(例如,就在 Mocha 主页上,有 mochajs.org/#wallabyjs)。
-
非常感谢...会检查它..
-
您是如何获得那里显示的覆盖率报告的?
标签: node.js mocha.js code-coverage