Пример #1
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <exception cref="StrykerInputException">For managed exceptions</exception>
        /// <param name="options">The user options</param>
        public StrykerRunResult RunMutationTest(StrykerOptions options)
        {
            // start stopwatch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Create output dir with gitignore
            _fileSystem.Directory.CreateDirectory(options.OutputPath);
            _fileSystem.File.Create(Path.Combine(options.OutputPath, ".gitignore")).Close();
            using (var file = _fileSystem.File.CreateText(Path.Combine(options.OutputPath, ".gitignore")))
            {
                file.WriteLine("*");
            }

            // setup logging
            ApplicationLogging.ConfigureLogger(options.LogOptions);
            var logger = ApplicationLogging.LoggerFactory.CreateLogger <StrykerRunner>();

            logger.LogDebug("Stryker started with options: {0}",
                            JsonConvert.SerializeObject(options, new StringEnumConverter()));

            try
            {
                // initialize
                _reporter = ReporterFactory.Create(options);
                _initialisationProcess = _initialisationProcess ?? new InitialisationProcess();
                _input = _initialisationProcess.Initialize(options);

                _mutationTestProcess = _mutationTestProcess ?? new MutationTestProcess(
                    mutationTestInput: _input,
                    reporter: _reporter,
                    mutationTestExecutor: new MutationTestExecutor(_input.TestRunner));

                // initial test
                _input.TimeoutMs = _initialisationProcess.InitialTest(options);

                // mutate
                _mutationTestProcess.Mutate(options);

                // coverage
                var coverage = _initialisationProcess.GetCoverage(options);

                _mutationTestProcess.Optimize(coverage);

                // test mutations and return results
                return(_mutationTestProcess.Test(options));
            }
            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);
            }
        }
Пример #2
0
        public void ReporterFactory_CreatesRequestedReporters(string option, Type reporter)
        {
            BroadcastReporter result = (BroadcastReporter)ReporterFactory.Create(new StrykerOptions(reporters: new[] { option }));

            result.ShouldBeOfType(typeof(BroadcastReporter));
            result.Reporters.ShouldHaveSingleItem().ShouldBeOfType(reporter);
        }
Пример #3
0
        /// <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)
        {
            // start stopwatch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // setup logging
            ApplicationLogging.ConfigureLogger(options.LogOptions, initialLogMessages);
            var logger = ApplicationLogging.LoggerFactory.CreateLogger <StrykerRunner>();

            logger.LogDebug("Stryker started with options: {0}",
                            JsonConvert.SerializeObject(options, new StringEnumConverter()));

            try
            {
                // initialize
                if (_reporter == null)
                {
                    _reporter = ReporterFactory.Create(options);
                }

                _initialisationProcess ??= new InitialisationProcess();

                _input = _initialisationProcess.Initialize(options);

                _mutationTestProcess ??= new MutationTestProcess(
                    mutationTestInput: _input,
                    reporter: _reporter,
                    mutationTestExecutor: new MutationTestExecutor(_input.TestRunner),
                    options: options);

                // initial test
                _input.TimeoutMs = _initialisationProcess.InitialTest(options, out var nbTests);

                // mutate
                _mutationTestProcess.Mutate();

                _mutationTestProcess.GetCoverage();

                _mutationTestProcess.FilterMutants();

                // test mutations and return results
                return(_mutationTestProcess.Test(options));
            }
            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);
            }
        }
Пример #4
0
        public void ReporterFactory_CreatesReplacementsForDeprecatedReporterOptions()
        {
            BroadcastReporter result = (BroadcastReporter)ReporterFactory.Create(new StrykerOptions(reporters: new[] { "ConsoleProgressBar", "ConsoleProgressDots", "ConsoleReport" }));

            result.ShouldBeOfType(typeof(BroadcastReporter));
            result.Reporters.ShouldContain(r => r is ConsoleDotProgressReporter);
            result.Reporters.ShouldContain(r => r is ClearTextReporter);
            result.Reporters.ShouldContain(r => r is ProgressReporter);
        }
Пример #5
0
        public void ReporterFactory_CreatesAllReporters()
        {
            BroadcastReporter result = (BroadcastReporter)ReporterFactory.Create(new StrykerOptions(reporters: new[] { "All" }));

            result.ShouldBeOfType(typeof(BroadcastReporter));
            result.Reporters.ShouldContain(r => r is JsonReporter);
            result.Reporters.ShouldContain(r => r is ConsoleDotProgressReporter);
            result.Reporters.ShouldContain(r => r is ConsoleReportReporter);
            result.Reporters.ShouldContain(r => r is ProgressReporter);
        }
        public void ReporterFactory_CreatesRequestedReporters(string option, Type reporter)
        {
            var branchProviderMock = new Mock <IGitInfoProvider>(MockBehavior.Loose);

            var target = new ReporterFactory();

            var result            = target.Create(new StrykerOptions(reporters: new[] { option }), branchProviderMock.Object);
            var broadcastReporter = result.ShouldBeOfType <BroadcastReporter>();

            broadcastReporter.Reporters.ShouldHaveSingleItem().ShouldBeOfType(reporter);
        }
Пример #7
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <exception cref="StrykerException">For managed exceptions</exception>
        /// <param name="options">The user options</param>
        public StrykerRunResult RunMutationTest(StrykerOptions options)
        {
            // start stopwatch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // setup logging
            ApplicationLogging.ConfigureLogger(options.LogOptions);
            var logger = ApplicationLogging.LoggerFactory.CreateLogger <StrykerRunner>();

            try
            {
                // initialize
                _reporter = ReporterFactory.Create(options);
                _initialisationProcess = _initialisationProcess ?? new InitialisationProcess();
                _input = _initialisationProcess.Initialize(options);

                _mutationTestProcess = _mutationTestProcess ?? new MutationTestProcess(
                    mutationTestInput: _input,
                    mutators: new List <IMutator> ()
                {
                    // the default list of mutators
                    new BinaryExpressionMutator(),
                    new BooleanMutator(),
                    new AssignmentStatementMutator(),
                    new PrefixUnaryMutator(),
                    new PostfixUnaryMutator(),
                    new CheckedMutator(),
                    new LinqMutator(),
                    new StringMutator(),
                    new InterpolatedStringMutator()
                },
                    reporter: _reporter,
                    mutationTestExecutor: new MutationTestExecutor(_input.TestRunner, _input.TimeoutMS));

                // mutate
                _mutationTestProcess.Mutate();

                // test mutations and return results
                return(_mutationTestProcess.Test(options));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred during the mutation test run ");
                throw;
            }
            finally {
                // log duration
                stopwatch.Stop();
                logger.LogInformation("Time Elapsed {0}", stopwatch.Elapsed);
            }
        }
Пример #8
0
        public void ReporterFactory_CreatesRequestedReporters(Reporter option, Type reporter)
        {
            var target  = new ReporterFactory();
            var options = new StrykerOptions {
                Reporters = new[] { option }
            };

            var result            = target.Create(options, _branchProviderMock.Object);
            var broadcastReporter = result.ShouldBeOfType <BroadcastReporter>();

            broadcastReporter.Reporters.ShouldHaveSingleItem().ShouldBeOfType(reporter);
        }
        public void ReporterFactory_CreatesReplacementsForDeprecatedReporterOptions()
        {
            var branchProviderMock = new Mock <IGitInfoProvider>(MockBehavior.Loose);

            var target = new ReporterFactory();

            var result            = target.Create(new StrykerOptions(reporters: new[] { "ConsoleProgressBar", "ConsoleProgressDots", "ConsoleReport" }), branchProvider: branchProviderMock.Object);
            var broadcastReporter = result.ShouldBeOfType <BroadcastReporter>();

            broadcastReporter.Reporters.ShouldContain(r => r is ConsoleDotProgressReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ClearTextReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ProgressReporter);
        }
Пример #10
0
        public static void Main()
        {
            // Инициализируем связи
            // Конфигурирование связей отделено от их использования
            ServiceLocator.RegisterService <IReportBuilder>(typeof(ReportBuilder));
            ServiceLocator.RegisterService <IReportSender>(typeof(SmsReportSender));
            ServiceLocator.RegisterService <IReporter>(typeof(Reporter));


            // Вызываем "сохраненную" ссылку на нужную реализацию
            var reporter = ReporterFactory.Create();

            reporter.SendReports();
        }
Пример #11
0
        public void ReporterFactory_CreatesAllReporters()
        {
            BroadcastReporter result = (BroadcastReporter)ReporterFactory.Create(new StrykerOptions(reporters: new[] { "All" }));

            result.ShouldBeOfType(typeof(BroadcastReporter));
            result.Reporters.ShouldContain(r => r is JsonReporter);
            result.Reporters.ShouldContain(r => r is HtmlReporter);
            result.Reporters.ShouldContain(r => r is ConsoleDotProgressReporter);
            result.Reporters.ShouldContain(r => r is ClearTextReporter);
            result.Reporters.ShouldContain(r => r is ProgressReporter);
            result.Reporters.ShouldContain(r => r is DashboardReporter);
            result.Reporters.ShouldContain(r => r is GitBaselineReporter);

            result.Reporters.Count().ShouldBe(7);
        }
Пример #12
0
        public static void ReporterSystem()
        {
            var pdfReporter = ReporterFactory.Create(ReportFormat.Pdf);

            var xmlReporter = ReporterFactory.Create(ReportFormat.Xml);

            var jsonReporter = ReporterFactory.Create(ReportFormat.Json);

            var xmlReport = xmlReporter.Report();

            var jsonReport = jsonReporter.Report();

            var pdfReport = pdfReporter.Report();

            Console.WriteLine(xmlReport);
            Console.WriteLine(jsonReport);
            Console.WriteLine(pdfReport);
        }
Пример #13
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <exception cref="StrykerException">For managed exceptions</exception>
        /// <param name="options">The user options</param>
        public void RunMutationTest(StrykerOptions options)
        {
            // start stopwatch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // setup logging
            ApplicationLogging.ConfigureLogger(options.LogOptions);
            var logger = ApplicationLogging.LoggerFactory.CreateLogger <StrykerRunner>();

            try
            {
                // validate options
                options = new StrykerOptionsValidator().Validate(options);

                // initialyze
                _reporter = ReporterFactory.Create(options.Reporter);
                _initialisationProcess = _initialisationProcess ?? new InitialisationProcess(_reporter);
                _input = _initialisationProcess.Initialize(options);

                _mutationTestProcess = _mutationTestProcess ?? new MutationTestProcess(
                    mutationTestInput: _input,
                    options: options,
                    reporter: _reporter,
                    mutationTestExecutor: new MutationTestExecutor(_input.TestRunner));

                // mutate
                _mutationTestProcess.Mutate();

                // test mutations
                _mutationTestProcess.Test();
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred during the mutationtest run ");
                throw;
            }
            finally {
                // log duration
                stopwatch.Stop();
                logger.LogInformation("Time Elapsed {0}", stopwatch.Elapsed);
            }
        }
        public void ReporterFactory_CreatesAllReporters()
        {
            var branchProviderMock = new Mock <IGitInfoProvider>(MockBehavior.Loose);

            var target = new ReporterFactory();

            var result = (BroadcastReporter)target.Create(new StrykerOptions(reporters: new[] { "All" }), branchProviderMock.Object);

            var broadcastReporter = result.ShouldBeOfType <BroadcastReporter>();

            broadcastReporter.Reporters.ShouldContain(r => r is JsonReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ConsoleDotProgressReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ClearTextReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ClearTextTreeReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ProgressReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is DashboardReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is GitBaselineReporter);

            result.Reporters.Count().ShouldBe(8);
        }
Пример #15
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <exception cref="StrykerInputException">For managed exceptions</exception>
        /// <param name="options">The user options</param>
        public StrykerRunResult RunMutationTest(StrykerOptions options)
        {
            // start stopwatch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // setup logging
            ApplicationLogging.ConfigureLogger(options.LogOptions);
            var logger = ApplicationLogging.LoggerFactory.CreateLogger <StrykerRunner>();

            try
            {
                // initialize
                _reporter = ReporterFactory.Create(options);
                _initialisationProcess = _initialisationProcess ?? new InitialisationProcess();
                _input = _initialisationProcess.Initialize(options);

                _mutationTestProcess = _mutationTestProcess ?? new MutationTestProcess(
                    mutationTestInput: _input,
                    excludedMutations: options.ExcludedMutations,
                    reporter: _reporter,
                    mutationTestExecutor: new MutationTestExecutor(_input.TestRunner, _input.TimeoutMS));

                // mutate
                _mutationTestProcess.Mutate(options);

                // test mutations and return results
                return(_mutationTestProcess.Test(options));
            }
            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);
            }
        }
Пример #16
0
        public void ReporterFactory_CreatesAllReporters()
        {
            var target  = new ReporterFactory();
            var options = new StrykerOptions {
                Reporters = new[] { Reporter.All }
            };

            var result = (BroadcastReporter)target.Create(options, _branchProviderMock.Object);

            var broadcastReporter = result.ShouldBeOfType <BroadcastReporter>();

            broadcastReporter.Reporters.ShouldContain(r => r is JsonReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ConsoleDotProgressReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ClearTextReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ClearTextTreeReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is ProgressReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is DashboardReporter);
            broadcastReporter.Reporters.ShouldContain(r => r is BaselineReporter);

            result.Reporters.Count().ShouldBe(8);
        }
Пример #17
0
        static void Main(string[] args)
        {
            #region 1
            // Инициализируем (регистрируем) связи
            // Конфигурирование связей отделено от их использования
            ServiceLocator.RegisterService <IReportBuilder>(typeof(ReportBuilder));
            ServiceLocator.RegisterService <IReportSender>(typeof(SmsReportSender));

            var reporter = new Reporter();
            reporter.SendReports();

            //или

            ServiceLocator.RegisterService <IReportBuilder>(typeof(ReportBuilder));
            ServiceLocator.RegisterService <IReportSender>(typeof(EmailReportSender));

            reporter = new Reporter();
            reporter.SendReports();

            #endregion

            #region 2
            ServiceLocator.RegisterService <IReportBuilder>(typeof(ReportBuilder));
            ServiceLocator.RegisterService <IReportSender>(typeof(SmsReportSender));
            ServiceLocator.RegisterService <IReporter>(typeof(Reporter));

            // Вызываем "сохраненную" ссылку на нужную реализацию
            var reporter1 = ReporterFactory.Create();
            reporter1.SendReports();

            //или

            ServiceLocator.RegisterService <IReportSender>(typeof(EmailReportSender));
            reporter1 = ServiceLocator.Resolve <IReporter>();

            reporter1.SendReports();
            #endregion
        }
Пример #18
0
        public void OnExecute()
        {
            if (EnableLogging)
            {
                XamarinSecurityScannerLogger.LogEvent = (m) => File.AppendAllText(LogFile, m);
            }

            if (IgnoreFile != null)
            {
                SetIgnoreObject();
            }

            Reporter = ReporterFactory.Create(Output);
            IScanner scanner = ScannerFactory.Create();

            Reporter.Start();
            Task task = scanner.Start(Path);

            task.Wait();

            Reporter.Finish();
            EnvironmentWrapper.Exit(Reporter.VulnerabilityCount < Threshold ? 0 : 1);
        }
        public void ReporterFactory_NameShouldCreateJustReporterType(StrykerOptions options, Type type)
        {
            var result = ReporterFactory.Create(options);

            result.ShouldBeOfType(type);
        }
Пример #20
0
        public void ReporterFactory_NameShouldCreateJustReporterType(string name, Type type)
        {
            var result = ReporterFactory.Create(name);

            result.ShouldBeOfType(type);
        }