private void Initialize()
 {
     try
     {
         projectOrchestrator = new ProjectOrchestrator();
         LogHelper.Info($"{ServiceName} has been initialized");
     }
     catch (Exception exception)
     {
         LogHelper.Error(exception);
     }
 }
Beispiel #2
0
 public StrykerRunner(IProjectOrchestrator projectOrchestrator = null, IEnumerable <IMutationTestProcess> mutationTestProcesses = null, IReporterFactory reporterFactory = null)
 {
     _projectOrchestrator   = projectOrchestrator ?? new ProjectOrchestrator();
     _mutationTestProcesses = mutationTestProcesses ?? new List <IMutationTestProcess>();
     _reporterFactory       = reporterFactory ?? new ReporterFactory();
 }
Beispiel #3
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <param name="options">The user options</param>
        /// <param name="loggerFactory">This loggerfactory will be used to create loggers during the stryker run</param>
        /// <exception cref="InputException">For managed exceptions</exception>
        public StrykerRunResult RunMutationTest(IStrykerInputs inputs, ILoggerFactory loggerFactory, IProjectOrchestrator projectOrchestrator = null)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            SetupLogging(loggerFactory);

            // Setup project orchestrator can't be done sooner since it needs logging
            projectOrchestrator ??= new ProjectOrchestrator();

            var options = inputs.ValidateAll();

            _logger.LogDebug("Stryker started with options: {@Options}", options);

            var reporters = _reporterFactory.Create(options);

            try
            {
                // Mutate
                _mutationTestProcesses = projectOrchestrator.MutateProjects(options, reporters).ToList();

                IReadOnlyProjectComponent rootComponent = AddRootFolderIfMultiProject(_mutationTestProcesses.Select(x => x.Input.ProjectInfo.ProjectContents).ToList(), options);

                _logger.LogInformation("{0} mutants created", rootComponent.Mutants.Count());

                AnalyseCoverage(options);

                // Filter
                foreach (var project in _mutationTestProcesses)
                {
                    project.FilterMutants();
                }

                // Report
                reporters.OnMutantsCreated(rootComponent);

                var allMutants    = rootComponent.Mutants;
                var mutantsNotRun = rootComponent.NotRunMutants().ToList();

                if (!mutantsNotRun.Any())
                {
                    if (allMutants.Any(x => x.ResultStatus == MutantStatus.Ignored))
                    {
                        _logger.LogWarning("It looks like all mutants with tests were ignored. Try a re-run with less ignoring!");
                    }
                    if (allMutants.Any(x => x.ResultStatus == MutantStatus.NoCoverage))
                    {
                        _logger.LogWarning("It looks like all non-ignored mutants are not covered by a test. Go add some tests!");
                    }
                    if (allMutants.Any(x => x.ResultStatus == MutantStatus.CompileError))
                    {
                        _logger.LogWarning("It looks like all mutants resulted in compile errors. Mutants sure are strange!");
                    }
                    if (!allMutants.Any())
                    {
                        _logger.LogWarning("It\'s a mutant-free world, nothing to test.");
                    }

                    reporters.OnAllMutantsTested(rootComponent);
                    return(new StrykerRunResult(options, rootComponent.GetMutationScore()));
                }

                // Report
                reporters.OnStartMutantTestRun(mutantsNotRun);

                // Test
                foreach (var project in _mutationTestProcesses)
                {
                    project.Test(project.Input.ProjectInfo.ProjectContents.Mutants.Where(x => x.ResultStatus == MutantStatus.NotRun).ToList());
                    project.Restore();
                }

                reporters.OnAllMutantsTested(rootComponent);

                return(new StrykerRunResult(options, rootComponent.GetMutationScore()));
            }
#if !DEBUG
            catch (Exception ex) when(!(ex is InputException))
            // let the exception be caught by the debugger when in debug
            {
                _logger.LogError(ex, "An error occurred during the mutation test run ");
                throw;
            }
#endif
            finally
            {
                // log duration
                stopwatch.Stop();
                _logger.LogInformation("Time Elapsed {0}", stopwatch.Elapsed);
            }
        }