Skip to content

Commit

Permalink
feat(test-runner): add nrOfTests metric
Browse files Browse the repository at this point in the history
Add `nrOfTests` metric to the `Survived` and `Killed` run results. This allows for calculation of the "tests per mutant metric"
  • Loading branch information
nicojs committed Aug 21, 2020
1 parent cb71558 commit 0eea448
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Expand Up @@ -2,7 +2,7 @@ import path = require('path');

import { factory, testInjector } from '@stryker-mutator/test-helpers';
import { expect } from 'chai';
import { KilledMutantRunResult, MutantRunStatus } from '@stryker-mutator/api/test_runner2';
import { MutantRunStatus } from '@stryker-mutator/api/test_runner2';
import { assertions } from '@stryker-mutator/test-helpers';

import JasmineTestRunner, { createJasmineTestRunner } from '../../src/JasmineTestRunner';
Expand Down Expand Up @@ -59,7 +59,12 @@ describe('JasmineRunner integration with code instrumentation', () => {
it('should be able to kill again after a mutant survived', async () => {
await sut.mutantRun(factory.mutantRunOptions({ activeMutant: factory.mutant({ id: 9 }) }));
const result = await sut.mutantRun(factory.mutantRunOptions({ activeMutant: factory.mutant({ id: 2 }) }));
const expected: KilledMutantRunResult = { killedBy: 'spec1', status: MutantRunStatus.Killed, failureMessage: 'Expected true to be falsy.' };
const expected = factory.killedMutantRunResult({
killedBy: 'spec1',
status: MutantRunStatus.Killed,
failureMessage: 'Expected true to be falsy.',
nrOfTests: 2, // spec0 and spec1
});
expect(result).deep.eq(expected);
});
});
Expand Down
Expand Up @@ -105,6 +105,12 @@ describe('Running an instrumented project', () => {
expect(result.failureMessage).eq('expected -3 to equal 7');
});

it('should bail after the first failed test', async () => {
const result = await sut.mutantRun(factory.mutantRunOptions({ activeMutant: factory.mutant({ id: 3 }) }));
assertions.expectKilled(result);
expect(result.nrOfTests).eq(1);
});

it('should be able to kill a mutant with filtered test', async () => {
const result = await sut.mutantRun(
factory.mutantRunOptions({ activeMutant: factory.mutant({ id: 3 }), testFilter: ['MyMath should be able to add two numbers'] })
Expand Down
1 change: 1 addition & 0 deletions packages/mocha-runner/test/unit/MochaTestRunner.spec.ts
Expand Up @@ -263,6 +263,7 @@ describe(MochaTestRunner.name, () => {
failureMessage: 'foo was baz',
killedBy: 'foo should be bar',
status: MutantRunStatus.Killed,
nrOfTests: 2,
};
expect(result).deep.eq(expectedResult);
});
Expand Down

0 comments on commit 0eea448

Please sign in to comment.