コード例 #1
0
 protected internal override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask("Running tests.", rootTestCommand.TestCount))
     {
         return RunTest(rootTestCommand, parentTestStep, options, progressMonitor);
     }
 }
コード例 #2
0
        /// <inheritdoc />
        protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            ThrowIfDisposed();

            using (progressMonitor.BeginTask(Resources.MbUnit2TestController_RunningMbUnitTests, 1))
            {
                if (progressMonitor.IsCanceled)
                    return new TestResult(TestOutcome.Canceled);

                if (options.SkipTestExecution)
                {
                    return SkipAll(rootTestCommand, parentTestStep);
                }
                else
                {
                    IList<ITestCommand> testCommands = rootTestCommand.GetAllCommands();

                    using (InstrumentedFixtureRunner fixtureRunner = new InstrumentedFixtureRunner(fixtureExplorer,
                        testCommands, progressMonitor, parentTestStep))
                    {
                        return fixtureRunner.Run();
                    }
                }
            }
        }
コード例 #3
0
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;
            progressMonitor.SetStatus(test.Name);

            // The first test should be an assembly test
            MSTestAssembly assemblyTest = testCommand.Test as MSTestAssembly;
            TestOutcome outcome;
            TestResult result;
            if (assemblyTest != null)
            {
                ITestContext assemblyContext = testCommand.StartPrimaryChildStep(parentTestStep);
                try
                {
                    MSTestRunner runner = MSTestRunner.GetRunnerForFrameworkVersion(frameworkVersion);

                    outcome = runner.RunSession(assemblyContext, assemblyTest,
                        testCommand, parentTestStep, progressMonitor);
                }
                catch (Exception ex)
                {
                    assemblyContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                    outcome = TestOutcome.Error;
                }

                result = assemblyContext.FinishStep(outcome, null);
            }
            else
            {
                result = new TestResult(TestOutcome.Skipped);
            }

            progressMonitor.Worked(1);
            return result;
        }
コード例 #4
0
        /// <inheritdoc />
        public ITestContext StartStep(TestStep testStep)
        {
            if (testStep == null)
                throw new ArgumentNullException("testStep");

            ITestContext parentContext = contextTracker.CurrentContext;
            ObservableTestContext context = new ObservableTestContext(this, testStep, parentContext);
            context.InitializeAndStartStep();
            return context;
        }
コード例 #5
0
        private static TestResult RunChildTests(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);

            bool passed = true;
            foreach (ITestCommand child in testCommand.Children)
                passed &= RunTest(child, testContext.TestStep, progressMonitor).Outcome.Status == TestStatus.Passed;

            return testContext.FinishStep(passed ? TestOutcome.Passed : TestOutcome.Failed, null);
        }
コード例 #6
0
        /// <summary>
        /// Runs the tests.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method can be called at most once during the lifetime of a test controller.
        /// </para>
        /// </remarks>
        /// <param name="rootTestCommand">The root test monitor.</param>
        /// <param name="parentTestStep">The parent test step, or null if starting a root step.</param>
        /// <param name="options">The test execution options.</param>
        /// <param name="progressMonitor">The progress monitor.</param>
        /// <returns>The combined result of the root test command.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="rootTestCommand"/>
        /// <paramref name="progressMonitor"/>, or <paramref name="options"/> is null.</exception>
        public TestResult Run(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            if (rootTestCommand == null)
                throw new ArgumentNullException("rootTestCommand");
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");
            if (options == null)
                throw new ArgumentNullException("options");

            return RunImpl(rootTestCommand, parentTestStep, options, progressMonitor);
        }
コード例 #7
0
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep,
            TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            // NOTE: This method has been optimized to minimize the total stack depth of the action
            //       by inlining blocks on the critical path that had previously been factored out.

            using (TestController testController = testControllerProvider(testCommand.Test))
            {
                if (testController != null)
                {
                    try
                    {
                        using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(testCommand.TestCount))
                        {
                            // Calling RunImpl directly instead of Run to minimize stack depth
                            // because we already know the arguments are valid.
                            return testController.RunImpl(testCommand, parentTestStep, options, subProgressMonitor);
                        }
                    }
                    catch (Exception ex)
                    {
                        ITestContext context = testCommand.StartPrimaryChildStep(parentTestStep);
                        context.LogWriter.Failures.WriteException(ex, "Fatal Exception in test controller");
                        return context.FinishStep(TestOutcome.Error, null);
                    }
                }
            }

            // Enter the scope of the test and recurse until we find a controller.
            progressMonitor.SetStatus(testCommand.Test.FullName);

            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);
            TestOutcome outcome = TestOutcome.Passed;

            foreach (ITestCommand monitor in testCommand.Children)
            {
                if (progressMonitor.IsCanceled)
                    break;

                TestResult childResult = RunTest(monitor, testContext.TestStep, options, progressMonitor);
                outcome = outcome.CombineWith(childResult.Outcome).Generalize();
            }

            if (progressMonitor.IsCanceled)
                outcome = TestOutcome.Canceled;

            TestResult result = testContext.FinishStep(outcome, null);

            progressMonitor.Worked(1);
            return result;
        }
コード例 #8
0
 protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask(Resources.XunitTestController_RunningXunitTests, rootTestCommand.TestCount))
     {
         if (options.SkipTestExecution)
         {
             return SkipAll(rootTestCommand, parentTestStep);
         }
         else
         {
             return RunTest(rootTestCommand, parentTestStep, progressMonitor);
         }
     }
 }
コード例 #9
0
 /// <inheritdoc />
 protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask(Resources.MSTestController_RunningMSTestTests, rootTestCommand.TestCount))
     {
         if (options.SkipTestExecution)
         {
             return(SkipAll(rootTestCommand, parentTestStep));
         }
         else
         {
             return(RunTest(rootTestCommand, parentTestStep, progressMonitor));
         }
     }
 }
コード例 #10
0
        public TestOutcome RunSession(ITestContext assemblyTestContext, MSTestAssembly assemblyTest,
            ITestCommand assemblyTestCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            DirectoryInfo tempDir = SpecialPathPolicy.For("MSTestAdapter").CreateTempDirectoryWithUniqueName();
            try
            {
                // Set the test results path.  Among other things, the test results path
                // will determine where the deployed test files go.
                string testResultsPath = Path.Combine(tempDir.FullName, "tests.trx");

                // Set the test results root directory.
                // This path determines both where MSTest searches for test files which
                // is used to resolve relative paths to test files in the "*.vsmdi" file.
                string searchPathRoot = Path.GetDirectoryName(assemblyTest.AssemblyFilePath);

                // Set the test metadata and run config paths.  These are just temporary
                // files that can go anywhere on the filesystem.  It happens to be convenient
                // to store them in the same temporary directory as the test results.
                string testMetadataPath = Path.Combine(tempDir.FullName, "tests.vsmdi");
                string runConfigPath = Path.Combine(tempDir.FullName, "tests.runconfig");

                progressMonitor.SetStatus("Generating test metadata file.");
                CreateTestMetadataFile(testMetadataPath,
                    GetTestsFromCommands(assemblyTestCommand.PreOrderTraversal), assemblyTest.AssemblyFilePath);

                progressMonitor.SetStatus("Generating run config file.");
                CreateRunConfigFile(runConfigPath);

                progressMonitor.SetStatus("Executing tests.");
                Executor executor = new Executor(this, assemblyTestContext, assemblyTestCommand);
                TestOutcome outcome = executor.Execute(testMetadataPath, testResultsPath,
                    runConfigPath, searchPathRoot);
                return outcome;
            }
            finally
            {
                try
                {
                    tempDir.Delete(true);
                }
                catch
                {
                    // Ignore I/O exceptions deleting temporary files.
                    // They will probably be deleted by the OS later on during a file cleanup.
                }
            }
        }
コード例 #11
0
        /// <inheritdoc />
        protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask(Resources.ConcordionTestController_RunningConcordionTests, rootTestCommand.TestCount))
            {
                if (progressMonitor.IsCanceled)
                    return new TestResult(TestOutcome.Canceled);

                if (options.SkipTestExecution)
                {
                    return SkipAll(rootTestCommand, parentTestStep);
                }
                else
                {
                    return RunTest(rootTestCommand, parentTestStep, progressMonitor);
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Creates an observable test context.
        /// </summary>
        /// <param name="manager">The test context manager.</param>
        /// <param name="testStep">The test step.</param>
        /// <param name="parent">The parent test context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="manager"/> or <paramref name="testStep"/> is null.</exception>
        public ObservableTestContext(ObservableTestContextManager manager, TestStep testStep, ITestContext parent)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");
            if (testStep == null)
                throw new ArgumentNullException("testStep");

            this.manager = manager;
            this.testStep = testStep;
            this.parent = parent;

            logWriter = new ObservableTestLogWriter(MessageSink, testStep.Id);
            externallyVisibleLogWriter = new FallbackMarkupDocumentWriter(logWriter,
                parent != null ? parent.LogWriter : new NullMarkupDocumentWriter());

            data = new UserDataCollection();
        }
コード例 #13
0
        private static TestResult RunTestFixture(ITestCommand testCommand, ConcordionTest concordionTest, TestStep parentTestStep)
        {
            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);

            // The magic happens here!
            var concordion = new ConcordionBuilder()
                                    .WithSource(concordionTest.Source)
                                    .WithTarget(concordionTest.Target)
                                    .WithSpecificationProcessingListener(new GallioResultRenderer())
                                    .Build();

            ConstructorInfo constructor = concordionTest.FixtureType.GetConstructor(Type.EmptyTypes);
            var fixture=constructor.Invoke(new object[]{});
            var summary = concordion.Process(concordionTest.Resource, fixture);
            bool passed = !(summary.HasFailures || summary.HasExceptions);
            testContext.AddAssertCount((int)summary.SuccessCount + (int)summary.FailureCount);
            return testContext.FinishStep(passed ? TestOutcome.Passed : TestOutcome.Failed, null);
        }
コード例 #14
0
        private static TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;
            progressMonitor.SetStatus(test.Name);

            TestResult result;
            ConcordionTest concordionTest = test as ConcordionTest;
            if (concordionTest == null)
            {
                result = RunChildTests(testCommand, parentTestStep, progressMonitor);
            }
            else
            {
                result = RunTestFixture(testCommand, concordionTest, parentTestStep);
            }

            progressMonitor.Worked(1);
            return result;
        }
コード例 #15
0
        private static TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;
            progressMonitor.SetStatus(test.Name);

            TestResult result;
            XunitTest xunitTest = test as XunitTest;
            if (xunitTest == null)
            {
                result = RunChildTests(testCommand, parentTestStep, progressMonitor);
            }
            else
            {
                result = RunTestFixture(testCommand, xunitTest.TypeInfo, parentTestStep);
            }

            progressMonitor.Worked(1);
            return result;
        }
コード例 #16
0
        /// <inheritdoc />
        protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            IList<ITestCommand> testCommands = rootTestCommand.GetAllCommands();
            using (progressMonitor.BeginTask(Resources.CSUnitTestController_RunningCSUnitTests, testCommands.Count))
            {
                if (progressMonitor.IsCanceled)
                {
                    return new TestResult(TestOutcome.Canceled);
                }

                if (options.SkipTestExecution)
                {
                    return SkipAll(rootTestCommand, parentTestStep);
                }

                using (RunnerMonitor monitor = new RunnerMonitor(testCommands, parentTestStep, progressMonitor))
                {
                    return monitor.Run(assemblyLocation);
                }
            }            
        }
コード例 #17
0
        /// <inheritdoc />
        protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            IList<Test> allTheTest = parentTestStep.Test.Children;
            PopulateSuiteFixtureData(allTheTest, options);
            using (progressMonitor.BeginTask(Resources.ConcordionTestController_RunningConcordionTests, rootTestCommand.TestCount))
            {
                if (progressMonitor.IsCanceled)
                {
                    return new TestResult(TestOutcome.Canceled);
                }

                if (options.SkipTestExecution)
                {
                    return SkipAll(rootTestCommand, parentTestStep);
                }
                else
                {
                    return RunTest(rootTestCommand, parentTestStep, progressMonitor);
                }
            }
        }
コード例 #18
0
    protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep,
                    TestExecutionOptions options, IProgressMonitor progressMonitor)
    {
      using (progressMonitor)
      {
        progressMonitor.BeginTask("Verifying Specifications", rootTestCommand.TestCount);

        if (options.SkipTestExecution)
        {
          return SkipAll(rootTestCommand, parentTestStep);
        }
        else
        {
          ITestContext rootContext = rootTestCommand.StartPrimaryChildStep(parentTestStep);
          TestStep rootStep = rootContext.TestStep;
          TestOutcome outcome = TestOutcome.Passed;

          _progressMonitor = progressMonitor;
          SetupRunOptions(options);
          SetupListeners(options);

          _listener.OnRunStart();

          foreach (ITestCommand command in rootTestCommand.Children)
          {
            MachineAssemblyTest assemblyTest = command.Test as MachineAssemblyTest;
            if( assemblyTest == null )
              continue;

            var assemblyResult = RunAssembly(assemblyTest, command, rootStep);
            outcome = outcome.CombineWith( assemblyResult.Outcome);
          }

          _listener.OnRunEnd();

          return rootContext.FinishStep( outcome, null);
        }
      }
    }
コード例 #19
0
        /// <inheritdoc />
        protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            ThrowIfDisposed();

            IList<ITestCommand> testCommands = rootTestCommand.GetAllCommands();
            using (progressMonitor.BeginTask(Resources.NUnitTestController_RunningNUnitTests, testCommands.Count))
            {
                if (progressMonitor.IsCanceled)
                    return new TestResult(TestOutcome.Canceled);

                if (options.SkipTestExecution)
                {
                    return SkipAll(rootTestCommand, parentTestStep);
                }
                else
                {
                    using (RunMonitor monitor = new RunMonitor(runner, testCommands, parentTestStep, progressMonitor))
                    {
                        return monitor.Run();
                    }
                }
            }
        }
コード例 #20
0
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor)
        {
            Test test = testCommand.Test;

            progressMonitor.SetStatus(test.Name);

            // The first test should be an assembly test
            MSTestAssembly assemblyTest = testCommand.Test as MSTestAssembly;
            TestOutcome    outcome;
            TestResult     result;

            if (assemblyTest != null)
            {
                ITestContext assemblyContext = testCommand.StartPrimaryChildStep(parentTestStep);
                try
                {
                    MSTestRunner runner = MSTestRunner.GetRunnerForFrameworkVersion(frameworkVersion);

                    outcome = runner.RunSession(assemblyContext, assemblyTest,
                                                testCommand, parentTestStep, progressMonitor);
                }
                catch (Exception ex)
                {
                    assemblyContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                    outcome = TestOutcome.Error;
                }

                result = assemblyContext.FinishStep(outcome, null);
            }
            else
            {
                result = new TestResult(TestOutcome.Skipped);
            }

            progressMonitor.Worked(1);
            return(result);
        }
コード例 #21
0
    TestResult RunContextTest(MachineAssemblyTest assemblyTest, MachineContextTest contextTest, ITestCommand command, TestStep parentTestStep)
    {
      ITestContext testContext = command.StartPrimaryChildStep(parentTestStep);

      GallioRunListener listener = new GallioRunListener(_listener, _progressMonitor, testContext, command.Children);

      IContextRunner runner = ContextRunnerFactory.GetContextRunnerFor(contextTest.Context);
      runner.Run(contextTest.Context, listener, _options, assemblyTest.GlobalCleanup, assemblyTest.SpecificationSupplements);

      return testContext.FinishStep(listener.Outcome, null);
    }
コード例 #22
0
    TestResult RunAssembly(MachineAssemblyTest assemblyTest, ITestCommand command, TestStep parentTestStep)
    {
      ITestContext assemblyContext = command.StartPrimaryChildStep(parentTestStep);

      AssemblyInfo assemblyInfo = new AssemblyInfo(assemblyTest.Name, assemblyTest.AssemblyFilePath);
      TestOutcome outcome = TestOutcome.Passed;

      _listener.OnAssemblyStart(assemblyInfo);
      assemblyTest.AssemblyContexts.Each(context => context.OnAssemblyStart());
      
      foreach (ITestCommand contextCommand in command.Children)
      {
        MachineContextTest contextTest = contextCommand.Test as MachineContextTest;
        if (contextTest == null) 
          continue;

        var contextResult = RunContextTest( assemblyTest, contextTest, contextCommand, assemblyContext.TestStep);
        outcome = outcome.CombineWith(contextResult.Outcome);
        assemblyContext.SetInterimOutcome(outcome);
      }

      assemblyTest.AssemblyContexts.Reverse().Each(context => context.OnAssemblyComplete());
      _listener.OnAssemblyEnd(assemblyInfo);

      return assemblyContext.FinishStep( outcome, null);
    }
コード例 #23
0
        /// <inheritdoc />
        public ITestContext StartStep(TestStep testStep)
        {
            if (testStep == null)
                throw new ArgumentNullException("testStep");
            if (testStep.Test != test)
                throw new ArgumentException("The test step must belong to the test associated with this test command.", "testStep");

            ITestContext context = contextManager.StartStep(testStep);
            context.Finishing += UpdateFailureCount;
            return context;
        }
コード例 #24
0
 /// <inheritdoc />
 public ITestContext StartPrimaryChildStep(TestStep parentTestStep)
 {
     TestStep primaryStep = new TestStep(test, parentTestStep);
     return StartStep(primaryStep);
 }
コード例 #25
0
ファイル: RunTask.cs プロジェクト: ndl/Gallio.BoostAdapter
        private bool TestUnitStart(string name, bool isSuite)
        {
            try
            {
                ProgressMonitor.SetStatus("Running " + name);

                Test test = TestModel.FindTest(GenerateTestId(name));
                TestStep step = new TestStep(test, testStepsStack_.Peek());
                TestResult result = new TestResult(TestOutcome.Passed);

                if (isSuite)
                {
                    CurrentTestSuite = test;
                    testsCountStack_.Push(0);
                }
                CurrentTest = test;

                step.IsTestCase = !isSuite;

                testStepsStack_.Push(step);
                testResultsStack_.Push(result);

                MessageSink.Publish(
                    new TestStepStartedMessage
                    {
                        Step = new TestStepData(step)
                    }
                );
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }

            return !ProgressMonitor.IsCanceled;
        }
コード例 #26
0
ファイル: TestContext.cs プロジェクト: dougrathbone/mbunit-v3
 /// <summary>
 /// Starts a child step of the context.
 /// </summary>
 /// <param name="name">The name of the step.</param>
 /// <param name="codeElement">The code element, or null if none.</param>
 /// <param name="isTestCase">True if the step represents an independent test case.</param>
 /// <returns>The context of the child step.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is null.</exception>
 internal TestContext StartChildStep(string name, ICodeElementInfo codeElement, bool isTestCase)
 {
     Model.Tree.TestStep testStep = new Model.Tree.TestStep(inner.TestStep.Test, inner.TestStep, name, codeElement, false);
     testStep.IsTestCase = isTestCase;
     testStep.IsDynamic = true;
     return PrepareContext(inner.StartChildStep(testStep), Sandbox.CreateChild());
 }
コード例 #27
0
        private static TestResult RunTestFixture(ITestCommand testCommand, XunitTypeInfoAdapter typeInfo,
            TestStep parentTestStep)
        {
            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);

            XunitTestClassCommand testClassCommand;
            try
            {
                testClassCommand = XunitTestClassCommandFactory.Make(typeInfo);
            }
            catch (Exception ex)
            {
                // Xunit can throw exceptions when making commands if the test is malformed.
                testContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                return testContext.FinishStep(TestOutcome.Failed, null);
            }

            return RunTestClassCommandAndFinishStep(testCommand, testContext, testClassCommand);
        }
コード例 #28
0
            public RunnerMonitor(IList<ITestCommand> testCommands, TestStep topTestStep, IProgressMonitor progressMonitor)
            {
                if (topTestStep == null)
                    throw new ArgumentNullException("topTestStep");
                if (progressMonitor == null)
                    throw new ArgumentNullException("progressMonitor");

                this.progressMonitor = progressMonitor;
                this.topTestStep = topTestStep;

                testContextStack = new Stack<ITestContext>();
                testCommandsByName = new Dictionary<string, ITestCommand>();

                Initialize(testCommands);

                progressMonitor.Canceled += Canceled;
            }
コード例 #29
0
        /// <summary>
        /// Recursively generates single test steps for each <see cref="ITestCommand" /> and
        /// sets the final outcome to <see cref="TestOutcome.Skipped" />.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This is useful for implementing fallback behavior when 
        /// <see cref="TestExecutionOptions.SkipTestExecution" /> is true.
        /// </para>
        /// </remarks>
        /// <param name="rootTestCommand">The root test command.</param>
        /// <param name="parentTestStep">The parent test step.</param>
        /// <returns>The combined result of the test commands.</returns>
        protected static TestResult SkipAll(ITestCommand rootTestCommand, TestStep parentTestStep)
        {
            ITestContext context = rootTestCommand.StartPrimaryChildStep(parentTestStep);

            foreach (ITestCommand child in rootTestCommand.Children)
                SkipAll(child, context.TestStep);

            return context.FinishStep(TestOutcome.Skipped, null);
        }
コード例 #30
0
 /// <summary>
 /// Implementation of <see cref="Run" /> called after argument validation has taken place.
 /// </summary>
 /// <param name="rootTestCommand">The root test command, not null.</param>
 /// <param name="parentTestStep">The parent test step, or null if none.</param>
 /// <param name="options">The test execution options, not null.</param>
 /// <param name="progressMonitor">The progress monitor, not null.</param>
 /// <returns>The combined result of the root test command.</returns>
 protected internal abstract TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor);
コード例 #31
0
        private static bool RunTestCommands(ITestCommand testCommand, XunitTestClassCommand testClassCommand,
            IEnumerable<XunitTestCommand> xunitTestCommands, TestStep parentTestStep, bool isPrimary)
        {
            bool passed = true;
            foreach (XunitTestCommand xunitTestCommand in xunitTestCommands)
            {
                TestStep testStep = new TestStep(testCommand.Test, parentTestStep,
                    testCommand.Test.Name, testCommand.Test.CodeElement, isPrimary);
                testStep.IsDynamic = !isPrimary;

                string displayName = xunitTestCommand.DisplayName;
                if (displayName != null)
                    testStep.Name = StripTypeNamePrefixFromDisplayName(testCommand.Test.CodeElement, displayName);

                ITestContext testContext = testCommand.StartStep(testStep);
                passed &= RunTestCommandAndFinishStep(testContext, testClassCommand, xunitTestCommand);
            }

            return passed;
        }
コード例 #32
0
        private static bool RunTestMethod(ITestCommand testCommand, MethodInfo methodInfo, XunitTestClassCommand testClassCommand,
            TestStep parentTestStep)
        {
            List<XunitTestCommand> xunitTestCommands;
            try
            {
                xunitTestCommands = new List<XunitTestCommand>(XunitTestCommandFactory.Make(testClassCommand,
                    XunitReflector.Wrap(methodInfo)));
            }
            catch (Exception ex)
            {
                // Xunit can throw exceptions when making commands if the test is malformed.
                ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);
                testContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                testContext.FinishStep(TestOutcome.Failed, null);
                return false;
            }

            if (xunitTestCommands.Count == 0)
                return true;

            if (xunitTestCommands.Count == 1)
                return RunTestCommands(testCommand, testClassCommand, xunitTestCommands, parentTestStep, true);

            // Introduce a common primary test step for theories.
            ITestContext primaryTestContext = testCommand.StartPrimaryChildStep(parentTestStep);
            bool result = RunTestCommands(testCommand, testClassCommand, xunitTestCommands, primaryTestContext.TestStep, false);
            primaryTestContext.FinishStep(result ? TestOutcome.Passed : TestOutcome.Failed, null);
            return result;
        }