4.2.1. Kiểm thử đơn vị, kiểm thử chấp thuận tự động

  • Kiểm thử ứng dụng: sử dụng công nghệ Karma - Jasmine cùng với một số Angular testing utilities để tiến hành kiểm thử cho dự án sử dụng framework Angular 2 của nhóm.

  • Sử dụng lệnh npm test để chạy kiểm thử và kết quả như sau:

Một số mã nguồn chạy kiểm thử:

Kiểm thử chức năng login:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { LoginComponent } from './login.component';

describe('LoginComponent', () => {

let component: LoginComponent;

let fixture: ComponentFixture<LoginComponent>;

beforeEach(async(() => {

TestBed.configureTestingModule\({

  declarations: \[ LoginComponent \]

}\)

.compileComponents\(\);

}));

beforeEach(() => {

fixture = TestBed.createComponent\(LoginComponent\);

component = fixture.componentInstance;

fixture.detectChanges\(\);

});

it('at login page', async(() => {

const fixture = TestBed.createComponent\(LoginComponent\);

const login = fixture.debugElement.componentInstance;

expect\(login\).toBeTruthy\(\);

}));

it('login succesfully when email is nguyentienviet and password is 123456', async(() => {

 const fixture = TestBed.createComponent\(LoginComponent\);

const login = fixture.debugElement.componentInstance;

expect\(login.email\).toEqual\('nguyentienviet'\);

expect\(login.password\).toEqual\('123456'\);

}));

it(`login faily when email is notvietatall and password is 123456`, async(() => {

 const fixture = TestBed.createComponent\(LoginComponent\);

const login = fixture.debugElement.componentInstance;

expect\(login.emailWrong\).toEqual\('notvietatall'\) && expect\(login.passwordWrong\).toEqual\('123456'\) ;

}));

results matching ""

    No results matching ""