public void ShouldPrintEachReasonWithCount() { var target = new FilteredMutantsLogger(_loggerMock.Object); var folder = new CsharpFolderComposite(); folder.Add(new CsharpFileLeaf() { Mutants = new Collection <Mutant>() { new Mutant() { ResultStatus = MutantStatus.Ignored, ResultStatusReason = "In excluded file" }, new Mutant() { ResultStatus = MutantStatus.Ignored, ResultStatusReason = "In excluded file" }, new Mutant() { ResultStatus = MutantStatus.Ignored, ResultStatusReason = "Mutator excluded" }, new Mutant() { ResultStatus = MutantStatus.Ignored, ResultStatusReason = "Mutator excluded" }, new Mutant() { ResultStatus = MutantStatus.Ignored, ResultStatusReason = "Mutator excluded" }, new Mutant() { ResultStatus = MutantStatus.CompileError, ResultStatusReason = "CompileError" }, new Mutant() { ResultStatus = MutantStatus.Ignored, ResultStatusReason = "In excluded file" }, new Mutant() { ResultStatus = MutantStatus.NotRun }, } }); target.OnMutantsCreated(folder.ToReadOnlyInputComponent()); _loggerMock.Verify(LogLevel.Information, "1 mutants got status CompileError. Reason: CompileError", Times.Once); _loggerMock.Verify(LogLevel.Information, "3 mutants got status Ignored. Reason: In excluded file", Times.Once); _loggerMock.Verify(LogLevel.Information, "3 mutants got status Ignored. Reason: Mutator excluded", Times.Once); _loggerMock.Verify(LogLevel.Information, "7 total mutants are skipped for the above mentioned reasons", Times.Once); _loggerMock.Verify(LogLevel.Information, "1 total mutants will be tested", Times.Once); _loggerMock.VerifyNoOtherCalls(); }
public void ShouldPrintNoMutations() { var target = new FilteredMutantsLogger(_loggerMock.Object); var folder = new CsharpFolderComposite(); folder.Add(new CsharpFileLeaf() { Mutants = new Collection <Mutant>() { } }); target.OnMutantsCreated(folder.ToReadOnlyInputComponent()); _loggerMock.Verify(LogLevel.Information, "0 total mutants will be tested", Times.Once); _loggerMock.VerifyNoOtherCalls(); }
/// <summary> /// Starts a mutation test run /// </summary> /// <exception cref="StrykerInputException">For managed exceptions</exception> /// <param name="options">The user options</param> /// <param name="initialLogMessages"> /// Allows to pass log messages that occured before the mutation test. /// The messages will be written to the logger after it was configured. /// </param> public StrykerRunResult RunMutationTest(StrykerOptions options, IEnumerable <LogMessage> initialLogMessages = null) { var stopwatch = new Stopwatch(); stopwatch.Start(); var reporters = _reporterFactory.Create(options); SetupLogging(options, initialLogMessages); try { _mutationTestProcesses = _projectOrchestrator.MutateProjects(options, reporters).ToList(); IFolderComposite rootComponent = new CsharpFolderComposite(); rootComponent.AddRange(_mutationTestProcesses.Select(x => x.Input.ProjectInfo.ProjectContents)); _logger.LogInformation("{0} mutants ready for test", rootComponent.Mutants.Count()); AnalyseCoverage(options); var readOnlyInputComponent = rootComponent.ToReadOnlyInputComponent(); reporters.OnMutantsCreated(readOnlyInputComponent); var allMutants = rootComponent.Mutants.ToList(); var mutantsNotRun = allMutants.Where(x => x.ResultStatus == MutantStatus.NotRun).ToList(); if (!mutantsNotRun.Any()) { if (allMutants.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 (allMutants.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 (!allMutants.Any()) { _logger.LogWarning("It\'s a mutant-free world, nothing to test."); } return(new StrykerRunResult(options, double.NaN)); } reporters.OnStartMutantTestRun(mutantsNotRun); foreach (var project in _mutationTestProcesses) { // test mutations project.Test(project.Input.ProjectInfo.ProjectContents.Mutants.Where(x => x.ResultStatus == MutantStatus.NotRun).ToList()); } reporters.OnAllMutantsTested(readOnlyInputComponent); return(new StrykerRunResult(options, readOnlyInputComponent.GetMutationScore())); } catch (Exception ex) when(!(ex is StrykerInputException)) { _logger.LogError(ex, "An error occurred during the mutation test run "); throw; } finally { // log duration stopwatch.Stop(); _logger.LogInformation("Time Elapsed {0}", stopwatch.Elapsed); } }