当我使用
ng test --code-coverage
运行测试时,我得到的代码覆盖范围是未知的,不确定是怎么回事。感谢您的任何帮助。
> ng test --code-coverage
10% building modules 1/1 modules 0 active26 06 2018 11:00:51.088:WARN [karma]: No captured browser, open http://localhost:9876/
26 06 2018 11:00:51.095:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
26 06 2018 11:00:51.095:INFO [launcher]: Launching browser Chrome with unlimited concurrency
26 06 2018 11:00:51.100:INFO [launcher]: Starting browser Chrome
26 06 2018 11:01:48.404:WARN [karma]: No captured browser, open http://localhost:9876/
26 06 2018 11:01:48.665:INFO [Chrome 67.0.3396 (Mac OS X 10.11.6)]: Connected on socket UhrUQZiU8ZuG8qRwAAAA with id 31579746
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1151 of 2149 (skipped 843) SUCCESS (0 secs / 0 secs)
26 06 2018 11:07:31.910:WARN [Chrome 67.0.3396 (Mac OS X 10.11.6)]: Disconnected (1 times), because no message in 10000 ms.
Chrome 67.0.3396 (Mac OS X 10.11.6) ERROR
Chrome 67.0.3396 (Mac OS X 10.11.6) ERROR
Disconnected, because no message in 10000 ms.
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1151 of 2149 (skipped 843) DISCONNECTED (5 mins 31.686 secs / 0 secs)
Chrome 67.0.3396 (Mac OS X 10.11.6) ERROR
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1151 of 2149 (skipped 843) DISCONNECTED (5 mins 31.686 secs / 0 secs)
=============================== Coverage summary ===============================
Statements : Unknown% ( 0/0 )
Branches : Unknown% ( 0/0 )
Functions : Unknown% ( 0/0 )
Lines : Unknown% ( 0/0 )
Chrome 67.0.3396 (Mac OS X 10.11.6): Executed 1295 of 2149 (skipped 854) DISCONNECTED (6 mins 49.413 secs / 0 secs)
答案 0 :(得分:1)
我遇到了同样的问题,并通过确保"sourceRoot"
中的angular.json
属性设置为项目源文件的根文件夹来解决此问题。
ng
cli uses the files in "sourceRoot"
to compute coverage。
sourceRoot
对于测试似乎没有任何其他作用,因此测试可以运行并通过,但是覆盖范围无效。
答案 1 :(得分:-1)
转到项目根目录下的./coverage文件夹。然后,您可以打开./coverage/index.html查看覆盖率报告。