Esempio n. 1
0
        private void DoWithTestRunner(Action <ITestRunner> action, IProgressMonitor progressMonitor,
                                      double initializationAndDisposalWorkUnits, IEnumerable <string> testRunnerExtensions)
        {
            if (testRunnerFactory == null)
            {
                throw new InvalidOperationException("A test runner factory must be set first.");
            }

            var testRunner = testRunnerFactory.CreateTestRunner();

            try
            {
                var testRunnerOptions = new TestRunnerOptions();
                var logger            = RuntimeAccessor.Logger;

                RegisterTestRunnerExtensions(testRunnerExtensions, testRunner);

                var subProgressMonitor = progressMonitor.CreateSubProgressMonitor(initializationAndDisposalWorkUnits / 2);
                testRunner.Initialize(testRunnerOptions, logger, subProgressMonitor);

                WireUpTestRunnerEvents(testRunner);

                action(testRunner);
            }
            finally
            {
                var subProgressMonitor = progressMonitor.CreateSubProgressMonitor(initializationAndDisposalWorkUnits / 2);
                testRunner.Dispose(subProgressMonitor);
            }
        }
Esempio n. 2
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());
        }
Esempio n. 3
0
        private void DoHandleMessage(IDotnetTest dotnetTest, Message message)
        {
            var testRunnerChannel = _reportingChannelFactory.CreateTestRunnerChannel();

            dotnetTest.StartListeningTo(testRunnerChannel);

            testRunnerChannel.Connect();

            var testRunner = _testRunnerFactory.CreateTestRunner(
                new RunTestsArgumentsBuilder(dotnetTest.PathToAssemblyUnderTest, testRunnerChannel.Port, message));

            dotnetTest.TestsToRun = message.Payload?.ToObject <RunTestsMessage>().Tests;

            var processStartInfo = testRunner.GetProcessStartInfo();

            _adapterChannel.Send(new Message
            {
                MessageType = TestMessageTypes.TestExecutionTestRunnerProcessStartInfo,
                Payload     = JToken.FromObject(processStartInfo)
            });
        }
Esempio n. 4
0
        private void DiscoverTests(IDotnetTest dotnetTest)
        {
            var testRunnerResults = Enumerable.Empty <Message>();

            try
            {
                var testRunnerChannel = _reportingChannelFactory.CreateTestRunnerChannel();

                dotnetTest.StartListeningTo(testRunnerChannel);

                testRunnerChannel.Connect();

                var testRunner = _testRunnerFactory.CreateTestRunner(
                    new DiscoverTestsArgumentsBuilder(dotnetTest.PathToAssemblyUnderTest, testRunnerChannel.Port));

                testRunner.RunTestCommand();
            }
            catch (TestRunnerOperationFailedException e)
            {
                _adapterChannel.SendError(e.Message);
            }
        }
Esempio n. 5
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);
        }