public StrykerRunResult Test(IEnumerable <Mutant> mutantsToTest) { if (!MutantsToTest(mutantsToTest)) { return(new StrykerRunResult(_options, double.NaN)); } TestMutants(mutantsToTest); _mutationTestExecutor.TestRunner.Dispose(); return(new StrykerRunResult(_options, _projectContents.ToReadOnlyInputComponent().GetMutationScore())); }
public StrykerRunResult Test(StrykerOptions options) { var viableMutantsCount = _projectInfo.Mutants.Count(x => x.CountForStats); var mutantsNotRun = _projectInfo.Mutants.Where(x => x.ResultStatus == MutantStatus.NotRun).ToList(); if (!mutantsNotRun.Any()) { if (_projectInfo.Mutants.Any(x => x.ResultStatus == MutantStatus.Ignored)) { _logger.LogWarning("It looks like all mutants with tests were excluded. Try a re-run with less exclusion!"); } if (_projectInfo.Mutants.Any(x => x.ResultStatus == MutantStatus.NoCoverage)) { _logger.LogWarning("It looks like all non-excluded mutants are not covered by a test. Go add some tests!"); } if (!_projectInfo.Mutants.Any()) { _logger.LogWarning("It\'s a mutant-free world, nothing to test."); return(new StrykerRunResult(options, double.NaN)); } } var mutantsToTest = mutantsNotRun; if (_options.Optimizations.HasFlag(OptimizationFlags.CoverageBasedTest)) { var testCount = _mutationTestExecutor.TestRunner.DiscoverNumberOfTests(); var toTest = mutantsNotRun.Sum(x => x.MustRunAgainstAllTests ? testCount : x.CoveringTests.Count); var total = testCount * viableMutantsCount; if (total > 0 && total != toTest) { _logger.LogInformation($"Coverage analysis will reduce run time by discarding {(total - toTest) / (double)total:P1} of tests because they would not change results."); } } else if (_options.Optimizations.HasFlag(OptimizationFlags.SkipUncoveredMutants)) { var total = viableMutantsCount; var toTest = mutantsToTest.Count(); if (total > 0 && total != toTest) { _logger.LogInformation($"Coverage analysis will reduce run time by discarding {(total - toTest) / (double)total:P1} of tests because they would not change results."); } } if (mutantsToTest.Any()) { var mutantGroups = BuildMutantGroupsForTest(mutantsNotRun); _reporter.OnStartMutantTestRun(mutantsNotRun, _mutationTestExecutor.TestRunner.Tests); Parallel.ForEach( mutantGroups, new ParallelOptions { MaxDegreeOfParallelism = options.ConcurrentTestrunners }, mutants => { var testMutants = new HashSet <Mutant>(); _mutationTestExecutor.Test(mutants, _input.TimeoutMs, (testedMutants, failedTests, ranTests, timedOutTest) => { var mustGoOn = !options.Optimizations.HasFlag(OptimizationFlags.AbortTestOnKill); foreach (var mutant in testedMutants) { mutant.AnalyzeTestRun(failedTests, ranTests, timedOutTest); if (mutant.ResultStatus == MutantStatus.NotRun) { mustGoOn = true; } else if (!testMutants.Contains(mutant)) { testMutants.Add(mutant); _reporter.OnMutantTested(mutant); } } return(mustGoOn); }); foreach (var mutant in mutants) { if (mutant.ResultStatus == MutantStatus.NotRun) { _logger.LogWarning($"Mutation {mutant.Id} was not fully tested."); } else if (!testMutants.Contains(mutant)) { _reporter.OnMutantTested(mutant); } } }); } _reporter.OnAllMutantsTested(_projectInfo.ToReadOnlyInputComponent()); _mutationTestExecutor.TestRunner.Dispose(); return(new StrykerRunResult(options, _projectInfo.ToReadOnlyInputComponent().GetMutationScore())); }