2017-01-20 2 views
4

私はUnit Testing in Angular2を初めて使用しています。コード範囲がangular-clikarmaの設定があります。私はng-testコマンドを実行し、コードカバレッジレポートを開いた。私は1x3xなどと、そのカバレッジレポートのコード行番号を見ました。私のカバレッジレポートイメージを見つけてください。Angular2ユニットテストのカルマコードカバレッジレポートでは、1x 3xなどは何を意味しますか?

enter image description here

は、ここに私のテストケースコード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などの重要性が何であるかを理解していなかったです。その重要性を知る上で助けてください。

答えて

7

これは、行が実行された回数を表します。あなたのコードによると

があなたのtitleフィールドを見てとることができます:

をそれは最初に実行されます:expect(app).toBeTruthy();

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

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

それが言うだから、なぜですそれの左に3倍。

+0

答えてくれてありがとう@echonax。あなたが忘れてしまった情報が他にもある場合は、私を共有してください。そうでない場合は、あなたの答えでそれを詳述することができます。もう一度、ありがとうございます。あなたの答えを受け入れる。 –

+0

@IsettyRavitejakumarあなたの質問を更新したので、私は自分の答えを更新しました。しかし、それには大きな意味はありません。おそらく、行が膨大な回数実行された場合、その行が不必要に使用されているかどうかチェックしたいかもしれませんが、大したことではないでしょうか。 – echonax

関連する問題