Reputation: 172
We've written some test cases for "Testing component." But how do we categorize test case is unit or e2e in Angular.
Upvotes: 1
Views: 482
Reputation: 538
This is how I see it:
Unit test: Test classes
Integration test: Test component (class + template) using ComponentFixture
E2E: Mimic user inputs using Protractor and Selenium
Upvotes: 0
Reputation: 1513
The difference between unit test and e2e test is what's tested?
e2e tests your view and depend of your framework/library and the unit test tests your business logic.
If I have a reference of your angular component it's certainly an e2e test, something like this:
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();
});
});
If you generate your component with angular CLI, a .spec.ts file is always generate with .css, .html and .ts.
If you have no reference to angular of any another third part framework. Your test will be a unit test. Something like this:
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)
})
})
After that, you have specification test, integration test, etc...
Upvotes: 2