2017-01-20 7 views
4

단위 테스트를 처음 접했습니다. 코드 범위가 angular-clikarma 설정이 있습니다. 명령 ng-test를 실행하고 코드 커버리지 보고서를 열었습니다. 나는 1x, 3x 등을 그 커버리지 리포트의 코드 라인 번호와 함께 보았다. 내 보험 보고서 이미지를 찾으십시오.Angular2 Unit 테스트의 카르마 코드 커버리지 보고서에서 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

라인이 실행 된 횟수를 나타냅니다.

그것은 먼저 실행됩니다 : expect(app).toBeTruthy();

둘째 : expect(app.title).toEqual('app works!');

셋째, 코드에 따르면

당신의 title 필드에서 살펴 수 있습니다 그것이 말하는 이유 expect(compiled.querySelector('h1').textContent).toContain('app works!');

그래서 그건 그것의 왼쪽에 3 배.

+0

답장을 보내 주셔서 감사합니다 @echonax. 더 이상 알려주지 못했던 정보가 더 있으면 나와 공유하십시오. 대답에 자세히 설명해주십시오. 다시 한번 대단히 감사합니다. 당신의 대답을 수락하십시오. –

+0

@IsettyRavitejakumar 질문을 업데이트 할 때 답변을 업데이트했습니다. 그러나 그것의 의미심장 한 중요성이 없다. 어쩌면 라인이 엄청나게 실행된다면, 그 라인이 불필요하게 사용되는지 체크하고 싶을 지 모르지만 나는 그것이 사실 일지는 의심 스럽다. – echonax