我们为"测试组件编写了一些测试用例。"但是我们如何将测试用例分类为Angular中的unit或e2e。
答案 0 :(得分:2)
单元测试和e2e测试之间的区别是经过测试的?
e2e 测试您的视图并依赖于您的框架/库,单元测试测试您的业务逻辑。
如果我有一个角度分量的参考,那肯定是 e2e测试,就像这样:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoaderComponent } from './loader.component';
describe('LoaderComponent', () => {
let component: LoaderComponent;
let fixture: ComponentFixture<LoaderComponent>; //<- ref of the angular component
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoaderComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
});
如果使用角度CLI生成组件,则始终使用.css,.html和.ts生成.spec.ts文件。
如果您没有参考任何其他第三方框架的角度。您的测试将是单元测试。像这样:
describe("Determine min or max ticket per person", () => {
it('Should return the max if the min is greater', () => {
const min = 10
const max = 5
expect(TicketDataSpecification.determineMinPerPerson(min, max)).toEqual(max)
})
it('Should return the min if the max is less', () => {
const min = 10
const max = 5
expect(TicketDataSpecification.determineMaxPerPerson(min, max)).toEqual(min)
})
it('Should return the quantity if the min is greater', () => {
const min = 10
const quantity = 5
expect(TicketDataSpecification.determineMinPerPersonWithQuantity(min, quantity)).toEqual(quantity)
})
it('Should return the quantity if the max is greater', () => {
const max = 10
const quantity = 5
expect(TicketDataSpecification.determineMaxPerPersonWithQuantity(max, quantity)).toEqual(quantity)
})
})
之后,您有规范测试,集成测试等......
答案 1 :(得分:0)
这是我的看法:
单元测试:测试类
集成测试:使用ComponentFixture测试组件(类+模板)
端到端:使用量角器和硒模仿用户输入