簡體   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