Пример #1
0
        public MasterTestRunner(IServiceLocator services, TestPackage package)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            _services   = services;
            TestPackage = package;

            // Get references to the services we use
            _projectService    = _services.GetService <IProjectService>();
            _testRunnerFactory = _services.GetService <ITestRunnerFactory>();

            _packageAnalyzer = _services.GetService <TestPackageAnalyzer>();
            _runtimeService  = _services.GetService <IRuntimeFrameworkService>();

            _eventDispatcher = _services.GetService <TestEventDispatcher>();

            // Last chance to catch invalid settings in package,
            // in case the client runner missed them.
            _packageAnalyzer.ValidatePackageSettings(package);
        }
Пример #2
0
        public MasterTestRunner(IServiceLocator services, TestPackage package)
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            _services   = services;
            TestPackage = package;

            // Get references to the services we use
            _projectService    = _services.GetService <IProjectService>();
            _testRunnerFactory = _services.GetService <ITestRunnerFactory>();

#if !NETSTANDARD1_6 && !NETSTANDARD2_0
            _runtimeService = _services.GetService <IRuntimeFrameworkService>();
#endif
#if !NETSTANDARD1_6
            _extensionService = _services.GetService <ExtensionService>();
#endif

            // Last chance to catch invalid settings in package,
            // in case the client runner missed them.
            ValidatePackageSettings();
        }
Пример #3
0
 public TestLoader(TestEventDispatcher eventDispatcher, IAssemblyWatcher assemblyWatcher)
 {
     this.events  = eventDispatcher;
     this.watcher = assemblyWatcher;
     this.factory = new DefaultTestRunnerFactory();
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
 }
 public GetTestRunnerProcessStartInfoMessageHandler(
     ITestRunnerFactory testRunnerFactory,
     IReportingChannel adapterChannel,
     IReportingChannelFactory reportingChannelFactory)
 {
     _testRunnerFactory = testRunnerFactory;
     _adapterChannel = adapterChannel;
     _reportingChannelFactory = reportingChannelFactory;
 }
Пример #5
0
        public void SetTestRunnerFactory(ITestRunnerFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            testRunnerFactory = factory;
        }
Пример #6
0
 public GetTestRunnerProcessStartInfoMessageHandler(
     ITestRunnerFactory testRunnerFactory,
     IReportingChannel adapterChannel,
     IReportingChannelFactory reportingChannelFactory)
 {
     _testRunnerFactory       = testRunnerFactory;
     _adapterChannel          = adapterChannel;
     _reportingChannelFactory = reportingChannelFactory;
 }
 public TestDiscoveryStartMessageHandler(
     ITestRunnerFactory testRunnerFactory,
     IReportingChannel adapterChannel,
     IReportingChannelFactory reportingChannelFactory)
 {
     _testRunnerFactory = testRunnerFactory;
     _adapterChannel = adapterChannel;
     _reportingChannelFactory = reportingChannelFactory;
 }
Пример #8
0
 public TestDiscoveryStartMessageHandler(
     ITestRunnerFactory testRunnerFactory,
     IReportingChannel adapterChannel,
     IReportingChannelFactory reportingChannelFactory)
 {
     _testRunnerFactory       = testRunnerFactory;
     _adapterChannel          = adapterChannel;
     _reportingChannelFactory = reportingChannelFactory;
 }
Пример #9
0
        public static IDotnetTest AddTestDiscoveryMessageHandlers(
            this IDotnetTest dotnetTest,
            IReportingChannel adapterChannel,
            IReportingChannelFactory reportingChannelFactory,
            ITestRunnerFactory testRunnerFactory)
        {
            dotnetTest.AddMessageHandler(
                new TestDiscoveryStartMessageHandler(testRunnerFactory, adapterChannel, reportingChannelFactory));

            return(dotnetTest);
        }
Пример #10
0
        /// <inheritdoc />
        public ITestRunner CreateTestRunner(string factoryName)
        {
            ITestRunnerFactory factory = GetFactory(factoryName);

            if (factory == null)
            {
                throw new InvalidOperationException(String.Format("There is no test runner factory named '{0}'.", factoryName));
            }

            return(factory.CreateTestRunner());
        }
Пример #11
0
        public MasterTestRunner(IServiceLocator services, TestPackage package)
        {
            _services = services;
            TestPackage = package;

            _testRunnerFactory = _services.GetService<ITestRunnerFactory>();
            _projectService = _services.GetService<IProjectService>();
            _runtimeService = _services.GetService<IRuntimeFrameworkService>();
            _extensionService = _services.GetService<ExtensionService>();
            _engineRunner = _testRunnerFactory.MakeTestRunner(package);
        }
Пример #12
0
        public MasterTestRunner(IServiceLocator services, TestPackage package)
        {
            _services   = services;
            TestPackage = package;

            _testRunnerFactory = _services.GetService <ITestRunnerFactory>();
            _projectService    = _services.GetService <IProjectService>();
            _runtimeService    = _services.GetService <IRuntimeFrameworkService>();
            _extensionService  = _services.GetService <ExtensionService>();
            _engineRunner      = _testRunnerFactory.MakeTestRunner(package);
        }
Пример #13
0
        public static IDotnetTest AddTestDiscoveryMessageHandlers(
            this IDotnetTest dotnetTest,
            IReportingChannel adapterChannel,
            IReportingChannelFactory reportingChannelFactory,
            ITestRunnerFactory testRunnerFactory)
        {
            dotnetTest.AddMessageHandler(
                new TestDiscoveryStartMessageHandler(testRunnerFactory, adapterChannel, reportingChannelFactory));

            return dotnetTest;
        }
        public AggregatingTestRunner(IServiceLocator services, TestPackage package) : base(package)
        {
            _testRunnerFactory = services.GetService <ITestRunnerFactory>();

            _packageList = new List <TestPackage>(package.Select(p => !p.HasSubPackages()));
            Runners      = new List <ITestEngineRunner>();
            foreach (var subPackage in _packageList)
            {
                Runners.Add(_testRunnerFactory.MakeTestRunner(subPackage));
            }
        }
Пример #15
0
        public static IDotnetTest AddTestRunMessageHandlers(
            this IDotnetTest dotnetTest,
            IReportingChannel adapterChannel,
            IReportingChannelFactory reportingChannelFactory,
            ITestRunnerFactory testRunnerFactory)
        {
            dotnetTest.AddMessageHandler(new GetTestRunnerProcessStartInfoMessageHandler(
                                             testRunnerFactory,
                                             adapterChannel,
                                             reportingChannelFactory));

            return(dotnetTest);
        }
Пример #16
0
        public static IDotnetTest AddTestRunMessageHandlers(
            this IDotnetTest dotnetTest,
            IReportingChannel adapterChannel,
            IReportingChannelFactory reportingChannelFactory,
            ITestRunnerFactory testRunnerFactory)
        {
            dotnetTest.AddMessageHandler(new GetTestRunnerProcessStartInfoMessageHandler(
                testRunnerFactory,
                adapterChannel,
                reportingChannelFactory));

            return dotnetTest;
        }
 public AgentRunner(int runnerID)
     : base(runnerID) 
 {
     this.factory = new InProcessTestRunnerFactory();
 }
Пример #18
0
        internal static int Run(
            string[] args,
            ITestRunnerFactory testRunnerFactory,
            Func <ITestRunner, IEventListener, ICoverageAnalysisResult, IMutationTestRunner> mutationTestRunnerFactory,
            Func <IEventListener, ICoverageAnalyser> coverageAnalyserFactory,
            ISourceControlIntegration sourceControlIntegration,
            IOutputWriter outputWriter)
        {
            try
            {
                outputWriter.WriteLine($"Fettle v{AssemblyVersionInformation.AssemblyVersion}");

                var parsedArgs = CommandLineArguments.Parse(args, outputWriter);
                if (!parsedArgs.Success)
                {
                    return(ExitCodes.ConfigOrArgsAreInvalid);
                }

                var validationErrors = parsedArgs.Config.Validate().ToList();
                if (validationErrors.Any())
                {
                    OutputValidationErrors(validationErrors, outputWriter);
                    return(ExitCodes.ConfigOrArgsAreInvalid);
                }

                if (!string.IsNullOrEmpty(parsedArgs.Config.CustomTestRunnerCommand) &&
                    !parsedArgs.ConsoleOptions.SkipCoverageAnalysis)
                {
                    WarnThatOptionsAreIncompatibleWithCoverageAnalysis(outputWriter);
                }

                if (parsedArgs.ConsoleOptions.ModificationsOnly)
                {
                    var result = FindLocallyModifiedSourceFiles(sourceControlIntegration, parsedArgs.Config, outputWriter);
                    if (!result.Success)
                    {
                        outputWriter.WriteFailureLine("Failed to find local modifications.");
                        return(ExitCodes.UnexpectedError);
                    }

                    parsedArgs.Config.LocallyModifiedSourceFiles = result.Files;
                }

                if (!parsedArgs.Config.HasAnyMutatableDocuments().Result)
                {
                    outputWriter.WriteLine("No source files found to mutate (or none matched the filters), exiting.");
                    return(ExitCodes.Success);
                }

                var eventListener = CreateEventListener(outputWriter, parsedArgs.ConsoleOptions.Verbosity);

                ICoverageAnalysisResult coverageResult = null;
                var shouldDoCoverageAnalysis           = !parsedArgs.Config.HasCustomTestRunnerCommand && !parsedArgs.ConsoleOptions.SkipCoverageAnalysis;
                if (shouldDoCoverageAnalysis)
                {
                    var analyser = coverageAnalyserFactory(eventListener);
                    coverageResult = AnalyseCoverage(analyser, outputWriter, parsedArgs.Config);

                    if (!coverageResult.WasSuccessful)
                    {
                        OutputCoverageAnalysisError(coverageResult.ErrorDescription, outputWriter);
                        return(ExitCodes.ConfigOrArgsAreInvalid);
                    }
                }

                var testRunner = parsedArgs.Config.HasCustomTestRunnerCommand ?
                                 testRunnerFactory.CreateCustomTestRunner(parsedArgs.Config.CustomTestRunnerCommand, parsedArgs.Config.BaseDirectory) :
                                 testRunnerFactory.CreateNUnitTestRunner();

                var mutationTestRunner = mutationTestRunnerFactory(testRunner, eventListener, coverageResult);
                var mutationTestResult = PerformMutationTesting(mutationTestRunner, parsedArgs.Config, outputWriter);
                if (mutationTestResult.Errors.Any())
                {
                    outputWriter.WriteFailureLine("Unable to perform mutation testing:");
                    mutationTestResult.Errors.ToList().ForEach(e => outputWriter.WriteFailureLine($"==> {e}"));
                    {
                        return(ExitCodes.ConfigOrArgsAreInvalid);
                    }
                }

                if (mutationTestResult.SurvivingMutants.Any())
                {
                    OutputAllSurvivorInfo(mutationTestResult.SurvivingMutants, outputWriter, parsedArgs.Config);
                    return(ExitCodes.SomeMutantsSurvived);
                }
                else
                {
                    outputWriter.WriteSuccessLine("No mutants survived.");
                    return(ExitCodes.Success);
                }
            }
            catch (Exception ex)
            {
                outputWriter.WriteFailureLine($"An error ocurred that Fettle didn't expect.{Environment.NewLine}{ex}");
                return(ExitCodes.UnexpectedError);
            }
        }
Пример #19
0
 public TestLoader(TestEventDispatcher eventDispatcher )
 {
     this.events = eventDispatcher;
     this.factory = new DefaultTestRunnerFactory();
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( OnUnhandledException );
 }
Пример #20
0
        private TestLauncherResult RunWithRuntime()
        {
            bool wasCanceled = false;

            ITestProjectManager testProjectManager = RuntimeAccessor.ServiceLocator.Resolve <ITestProjectManager>();

            TestProject consolidatedTestProject = ConsolidateTestProject(testProjectManager, ref wasCanceled);

            if (wasCanceled)
            {
                return(CreateResult(ResultCode.Canceled, testProject));
            }
            if (consolidatedTestProject == null)
            {
                return(CreateResult(ResultCode.InvalidArguments, testProject));
            }

            if (consolidatedTestProject.TestPackage.Files.Count == 0)
            {
                logger.Log(LogSeverity.Warning, "No test files to execute!");
                return(CreateResult(ResultCode.NoTests, consolidatedTestProject));
            }

            IReportManager reportManager = RuntimeAccessor.ServiceLocator.Resolve <IReportManager>();

            if (!ValidateReportFormats(reportManager, consolidatedTestProject))
            {
                return(CreateResult(ResultCode.InvalidArguments, consolidatedTestProject));
            }

            ITestRunnerManager testRunnerManager = RuntimeAccessor.ServiceLocator.Resolve <ITestRunnerManager>();
            ITestRunnerFactory testRunnerFactory = testRunnerManager.GetFactory(consolidatedTestProject.TestRunnerFactoryName);

            if (testRunnerFactory == null)
            {
                logger.Log(LogSeverity.Error, String.Format("Unrecognized test runner factory name: '{0}'.", consolidatedTestProject.TestRunnerFactoryName));
                return(CreateResult(ResultCode.InvalidArguments, consolidatedTestProject));
            }

            ITestRunner runner = testRunnerFactory.CreateTestRunner();
            var         result = new TestLauncherResult(new Report {
                TestPackage = new TestPackageData(TestProject.TestPackage)
            });

            try
            {
                DoRegisterExtensions(runner, consolidatedTestProject);
                DoInitialize(runner, ref wasCanceled);

                if (!wasCanceled)
                {
                    result = RunWithInitializedRunner(runner, consolidatedTestProject, reportManager);
                }
            }
            finally
            {
                DoDispose(runner, ref wasCanceled);
            }

            if (wasCanceled)
            {
                result.SetResultCode(ResultCode.Canceled);
            }

            return(result);
        }
Пример #21
0
 public AgentRunner(int runnerID)
     : base(runnerID)
 {
     this.factory = new InProcessTestRunnerFactory();
 }