繁体   English   中英

1x 3x等在角度单元测试中的业力代码覆盖率报告中意味着什么?

[英]what does 1x 3x etc mean in karma code coverage report in Angular Unit testing?

我是Angular的单元测试的新手。 我得到了代码覆盖率和angular-clikarma设置。 我运行了命令ng-test并打开了代码覆盖率报告。 我在该覆盖率报告中看到了1x3x等以及我的代码行号。 请找到我的报道图像。

在此输入图像描述

这是我的测试用例代码app.component.spec.ts

/* tslint:disable:no-unused-variable */

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        AppComponent
      ],
    });
  });

  it('should create the app', async(() => {
    let fixture = TestBed.createComponent(AppComponent);
    let app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  }));

  it(`should have as title 'app works!'`, async(() => {
    let fixture = TestBed.createComponent(AppComponent);
    let app = fixture.debugElement.componentInstance;
    expect(app.title).toEqual('app works!');
  }));

  it('should render title in a h1 tag', async(() => {
    let fixture = TestBed.createComponent(AppComponent);
    fixture.detectChanges();
    let compiled = fixture.debugElement.nativeElement;
    expect(compiled.querySelector('h1').textContent).toContain('app works!');
  }));
});

我不明白我的代码报告中1x,2x,3x等的重要性。 请帮助我了解其重要性。

它表示该行已执行的次数。

根据你的代码,让我们来看看你的title字段:

它首先被执行: expect(app).toBeTruthy();

第二: expect(app.title).toEqual('app works!');

第三种: expect(compiled.querySelector('h1').textContent).toContain('app works!');

所以这就是为什么它在左边说3x。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM