Angular 在测试中,如何确定哪一个是单元测试用例和e2e测试用例?
我们已经为“测试组件”编写了一些测试用例。但是我们如何在角度上将测试用例分为单元测试和e2e测试。单元测试和e2e测试之间的区别在于测试的是什么 e2e测试您的视图和框架/库的依赖性,单元测试测试您的业务逻辑 如果我有一个角度分量的参考,那肯定是e2e测试,类似这样:Angular 在测试中,如何确定哪一个是单元测试用例和e2e测试用例?,angular,unit-testing,e2e-testing,Angular,Unit Testing,E2e Testing,我们已经为“测试组件”编写了一些测试用例。但是我们如何在角度上将测试用例分为单元测试和e2e测试。单元测试和e2e测试之间的区别在于测试的是什么 e2e测试您的视图和框架/库的依赖性,单元测试测试您的业务逻辑 如果我有一个角度分量的参考,那肯定是e2e测试,类似这样: import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { LoaderComponent } from './loader
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();
});
});
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)
})
})
之后,您将进行规范测试、集成测试等。这就是我的看法:单元测试:测试类
集成测试:使用ComponentFixture测试组件(类+模板)
E2E:使用量角器和硒模拟用户输入太宽。如果它符合“单元测试”的定义,那么它就是单元测试。如果它符合“e2e”的定义,那么它就是e2e。我建议把你目前的考试发出去。可能还是太宽泛和属于,但至少可以回答。