Chutzpah覆盖率小于100%(由于私人方法?) [英] Chutzpah coverage result smaller than 100% (due to private methods?)

查看:157
本文介绍了Chutzpah覆盖率小于100%(由于私人方法?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Chutzpah测试我的JavaScript测试覆盖率。以下是运行单个测试文件时的覆盖结果示例 referenceFigureEdit.spec.js

I use Chutzpah to test my JavaScript test coverage. Here is an example for the coverage result when I run a single test file referenceFigureEdit.spec.js:

我预计保险范围为100%,但仅为91.07%。

I would expect the coverage to be 100% but it is only 91.07%.

点击第一行,我可以详细检查我的测试代码。突出显示未被测试覆盖的行:

Clicking on the first line I can inspect my tested code in detail. Lines that are "not covered by the test" are highlighted:

问题A

我怎样才能


  • 告诉Chutzpah这些方法是否已经实施或

  • 告诉Chutzpah不在报道结果中包含这些行?

对于成功覆盖的代码必须执行的位置/时间是否有一些限制?我在我的it-methods中调用了代理。在构建被测模块时是否需要调用它们?

Are there some restrictions on where/when code has to be executed to be part of the successful coverage? I call the delegates inside my it-methods. Do they already need to be called during the construction of the module under test?

我测试的代码定义了传递给构造函数的一些委托方法(例如showErrors)(例如new saveCommand(...,showErrors))。该代表的方法声明突出显示,不包含在coverage中。但是,这些代表实际上是在测试期间执行的,我希望覆盖范围是100%。

My tested code defines some delegate methods (e.g. "showErrors") that are passed to constructors (e.g. new saveCommand(..., showErrors)). The method declarations of that delegates are highlighted and not included in the coverage. However, those delegates are actually executed during the test and I would expect the coverage to be 100 %.

即使showErrors委托中的代码是私有的,我也想测试它(是否应该测试私有方法不是我的问题)。为了在我的测试中执行委托,我模拟了saveCommand。模拟的saveCommand发布传递的委托,在测试中我明确地调用它:

Even if the code in the showErrors delegate is private I would like to test it (whether private methods should be tested is not my question here). In order to execute the delegates in my tests, I mock the saveCommand. The mocked saveCommand publishes the passed delegate and in the test I explicitly call it:

sut.saveCommand.__showErrors();
expect(showAllMessagesSpy).toHaveBeenCalled();

测试成功执行,对我来说没问题。但是,覆盖率结果与预期不符。

The test executes successfully and is fine for me. However, the coverage result is not as expected.

问题B

引用文件错误处理程序的主要覆盖率结果。 js显示覆盖率为27.59%。我还没有对errorhandler.js进行测试。这个数字是否意味着在执行我的主文件referenceFigureEdit.js时会执行errorhandler.js的现有29个语句中的8个?我的主文件直接引用errorhandler.js但不直接引用utils.js。我在哪里可以找到一些关于如何正确解释这些子数字的文档,以及总计47.66%的目的是什么?

The main coverage results for the referenced file errorhandler.js shows a coverage of 27.59 %. I do not yet have a test for errorhandler.js. Does that number mean that 8 of the existing 29 statements of the errorhandler.js are executed while executing my main file referenceFigureEdit.js? My main file directly references errorhandler.js but does not directly reference utils.js. Where can I find some documentation on how to interpret those "sub-numbers" correctly and what is the purpose of the Total of 47.66% ?

推荐答案

我可以回答问题A:您可以使用chutzpah.json文件指定排除项:
CodeCoverageExcludes :[path1,path2,path3,etc]据我所知,你只能排除文件,不是特定的行。

I can answer Question A: You can use the chutzpah.json file to specify exclusions: "CodeCoverageExcludes": ["path1","path2","path3","etc"] As far as I know, you can only exclude files, though, not specific lines.

更新:是的,blanket.js是默认的代码覆盖率工具,它只排除在文件级别。

Update: yeah, blanket.js is the default code coverage tool, and it only excludes at the file level.

问题B我也想弄明白。

Question B I'm also trying to figure out.

这篇关于Chutzpah覆盖率小于100%(由于私人方法?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆