コード例 #1
0
ファイル: TestRunner.cs プロジェクト: robmaher/SpecFlow
        //TODO: rename this method to OnAfterLastStep (breaking change in generation!)
        public void CollectScenarioErrors()
        {
            HandleBlockSwitch(ScenarioBlock.None);

            if (RuntimeConfiguration.Current.TraceTimings)
            {
                ObjectContainer.ScenarioContext.Stopwatch.Stop();
                var duration = ObjectContainer.ScenarioContext.Stopwatch.Elapsed;
                testTracer.TraceDuration(duration, "Scenario: " + ObjectContainer.ScenarioContext.ScenarioInfo.Title);
            }

            if (ObjectContainer.ScenarioContext.TestStatus == TestStatus.OK)
            {
                return;
            }

            if (ObjectContainer.ScenarioContext.TestStatus == TestStatus.StepDefinitionPending)
            {
                var pendingSteps = ObjectContainer.ScenarioContext.PendingSteps.Distinct().OrderBy(s => s);
                errorProvider.ThrowPendingError(ObjectContainer.ScenarioContext.TestStatus, string.Format("{0}{2}  {1}",
                                                                                                          errorProvider.GetPendingStepDefinitionError().Message,
                                                                                                          string.Join(Environment.NewLine + "  ", pendingSteps.ToArray()),
                                                                                                          Environment.NewLine));
                return;
            }

            if (ObjectContainer.ScenarioContext.TestStatus == TestStatus.MissingStepDefinition)
            {
                var    missingSteps    = ObjectContainer.ScenarioContext.MissingSteps.Distinct().OrderBy(s => s);
                string bindingSkeleton =
                    stepDefinitionSkeletonProvider.GetBindingClassSkeleton(
                        string.Join(Environment.NewLine, missingSteps.ToArray()));
                errorProvider.ThrowPendingError(ObjectContainer.ScenarioContext.TestStatus, string.Format("{0}{2}{1}",
                                                                                                          errorProvider.GetMissingStepDefinitionError().Message,
                                                                                                          bindingSkeleton,
                                                                                                          Environment.NewLine));
                return;
            }

            if (ObjectContainer.ScenarioContext.TestError == null)
            {
                throw new InvalidOperationException("test failed with an unknown error");
            }

            ObjectContainer.ScenarioContext.TestError.PreserveStackTrace();
            throw ObjectContainer.ScenarioContext.TestError;
        }