I have created a basic template application with Angular 6 and I am trying to get Stryker Mutation testing working on it. On a basic home page:
import { Component } from '@angular/core';
/**
* Home Page Definition
*/
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss']
})
export class HomePage {}
I have a basic test file for this page:
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HomePage } from './home.page';
/**
* Home Page Test File
*/
describe('HomePage', () => {
let component: HomePage;
let fixture: ComponentFixture<HomePage>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [HomePage],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HomePage);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeDefined();
expect(component).toBeTruthy();
});
it('should be proper component', () => {
expect(component).toBeInstanceOf(HomePage);
});
});
While this passes and tests that the Home page will be created, I still have the
.
On the basic home page, the @Component has 3 fields that all generate mutant survivors since they are literal text. I am not sure how to write a test that will kill these mutant survivors.
It does not appear that Stryker has a method to ignore a section of code as an alternate if I cannot write tests to handle the condition.
You can test the component metadata annotations of a component instance which is fine as a starting point when doing TDD (Test-Driven Development), but you should quickly be able to replace it with proper tests which verifies actual behavior.
Note that runtime component metadata will be changed with the upcoming Angular Ivy internal rewrite.
A StackBlitz demonstrating this spec
Styles
Template
Test suite