コード例 #1
0
            private void StartStep(Report report, TestStepData step)
            {
                TestData    testData    = GetTestData(report, step.TestId);
                TestStepRun testStepRun = new TestStepRun(step);

                testStepRun.StartTime = DateTime.Now;

                TestStepState parentState;

                if (step.ParentId != null)
                {
                    parentState = GetTestStepState(step.ParentId);
                    parentState.TestStepRun.Children.Add(testStepRun);
                }
                else
                {
                    parentState = null;
                    report.TestPackageRun.RootTestStepRun = testStepRun;
                }

                TestStepState state = new TestStepState(parentState, testData, testStepRun);

                states.Add(step.Id, state);

                eventDispatcher.NotifyTestStepStarted(
                    new TestStepStartedEventArgs(report, testData, testStepRun));
            }
コード例 #2
0
 public void ConstructorTest()
 {
     TestStepData step = new TestStepData("id", "name", "fullName", "testId");
     TestStepRun testStepRun = new TestStepRun(step);
     Assert.AreSame(step, testStepRun.Step);
     Assert.Count(0, testStepRun.Children);
 }
コード例 #3
0
        public TestStepData LogStep(string TestCaseID, string Description, bool TakeScreenshot = true)
        {
            string ImageName = Utility.RemoveUnsafeChars(String.Format("{0}_{1}.png", DateTime.Now.ToString(), Description));

            string ImageLocation = "Failed To capture image.";

            if (TakeScreenshot)
            {
                try
                {
                    _driver.TakeScreenshot()
                    .SaveAsFile(Path.Combine(Utility.GetStepImageLocation(), ImageName), ImageFormat.Png);

                    ImageLocation = Path.Combine(Utility.GetStepImageLocation(), ImageName);
                }
                catch (Exception e)
                {
                    //Not something Fatal
                }
            }


            TestStepData StepData = new TestStepData(TestCaseID, _driver);

            StepData.Description   = Description;
            StepData.TestCaseID    = TestCaseID;
            StepData.ImageLocation = ImageLocation;
            StepData.Timestamp     = DateTime.Now;
            StepData.Log           = StepLog.Select(item => (string)item.Clone()).ToList();

            Console.WriteLine("\n" + StepData.Timestamp.ToString("g") + ":Step-" + StepData.Description);
            Console.WriteLine("\nScreenshot:" + StepData.ImageLocation);
            StepLog.Clear();
            return(StepData);
        }
コード例 #4
0
        public void ConstructorTest()
        {
            TestStepData step        = new TestStepData("id", "name", "fullName", "testId");
            TestStepRun  testStepRun = new TestStepRun(step);

            Assert.AreSame(step, testStepRun.Step);
            Assert.Count(0, testStepRun.Children);
        }
コード例 #5
0
ファイル: TestStepRun.cs プロジェクト: dougrathbone/mbunit-v3
        /// <summary>
        /// Creates a test run step.
        /// </summary>
        /// <param name="step">Information about the step.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="step" /> is null.</exception>
        public TestStepRun(TestStepData step)
            : this()
        {
            if (step == null)
                throw new ArgumentNullException(@"step");

            this.step = step;
        }
コード例 #6
0
 private void FinishRoot(Report report)
 {
     if (rootTestStepData != null)
     {
         rootTestStepResult.DurationInSeconds = rootTestStepStopwatch.Elapsed.TotalSeconds;
         FinishStep(report, rootTestStepData.Id, rootTestStepResult);
         rootTestStepData = null;
     }
 }
コード例 #7
0
        /// <summary>
        /// Creates a test run step.
        /// </summary>
        /// <param name="step">Information about the step.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="step" /> is null.</exception>
        public TestStepRun(TestStepData step)
            : this()
        {
            if (step == null)
            {
                throw new ArgumentNullException(@"step");
            }

            this.step = step;
        }
コード例 #8
0
        private string EndStepContinuation(TestStepData step, Action action)
        {
            if (step.Id == currentStepStack.Peek())
            {
                currentStepStack.Pop();
                action();
                return(SanitizeContinuationId(step.ParentId));
            }

            SaveContinuation(step.Id, () => EndStepContinuation(step, action));
            return(null);
        }
コード例 #9
0
        private string BeginStepContinuation(TestStepData step, Action action)
        {
            if (currentStepStack.Count == 0 || step.ParentId == currentStepStack.Peek())
            {
                currentStepStack.Push(step.Id);
                action();
                return(step.Id);
            }

            SaveContinuation(SanitizeContinuationId(step.ParentId), () => BeginStepContinuation(step, action));
            return(null);
        }
コード例 #10
0
        public void Step(string description)
        {
            TestStepData stepdata = Context.LogStep(TestCaseID, description);

            if (CaseData.StepList.Count > 0)
            {
                CaseData.StepList.Last().Log = stepdata.Log.Select(item => (string)item.Clone()).ToList();
            }

            CaseData.StepList.Add(stepdata);
            CaseData.StepList.Last().Log.Clear();
        }
コード例 #11
0
        /// <inheritdoc />
        public override Message Normalize()
        {
            TestStepData normalizedStep = Step.Normalize();

            if (ReferenceEquals(Step, normalizedStep))
                return this;

            return new TestStepStartedMessage()
            {
                Step = normalizedStep,
                CodeElement = codeElement
            };
        }
コード例 #12
0
        private TestStepRun CreateFakeTestStepRun(string id, bool isTestCase, TestOutcome outcome, params TestStepRun[] children)
        {
            var step = new TestStepData(id, "Name-" + id, "FullName-" + id, "Test-" + id);

            step.IsTestCase = isTestCase;
            var run = new TestStepRun(step);

            run.Result = new TestResult()
            {
                Outcome = outcome
            };
            run.Children.AddRange(children);
            return(run);
        }
コード例 #13
0
        /// <summary>
        /// Builds the tree under the specified root test step run.
        /// </summary>
        /// <param name="root">The root test step run.</param>
        /// <returns></returns>
        public static TestStepRunNode BuildTreeFromRoot(TestStepRun root)
        {
            if (root == null)
            {
                var step = new TestStepData(String.Empty, String.Empty, String.Empty, String.Empty);
                root        = new TestStepRun(step);
                root.Result = new TestResult();
            }

            int index = 0;
            var node  = new TestStepRunNode(root, null, index++);

            node.Children.AddRange(GetChildren(node, ref index));
            return(node);
        }
コード例 #14
0
        public static void AreEqual(TestStepData expected, TestStepData actual)
        {
            if (expected == null)
            {
                Assert.IsNull(actual);
                return;
            }

            AreEqual((TestComponentData)expected, actual);

            Assert.AreEqual(expected.FullName, actual.FullName);
            Assert.AreEqual(expected.ParentId, actual.ParentId);
            Assert.AreEqual(expected.TestId, actual.TestId);
            Assert.AreEqual(expected.IsPrimary, actual.IsPrimary);
            Assert.AreEqual(expected.IsTestCase, actual.IsTestCase);
            Assert.AreEqual(expected.IsDynamic, actual.IsDynamic);
        }
コード例 #15
0
            private TestStepData RedirectParentIdOfTestStepData(TestStepData step)
            {
                if (step.ParentId != null && rootTestStepIds.Contains(step.ParentId))
                {
                    TestStepData targetStep = new TestStepData(step.Id, step.Name, step.FullName, step.TestId)
                    {
                        CodeLocation  = step.CodeLocation,
                        CodeReference = step.CodeReference,
                        IsDynamic     = step.IsDynamic,
                        IsPrimary     = step.IsPrimary,
                        IsTestCase    = step.IsTestCase,
                        Metadata      = step.Metadata,
                        ParentId      = rootTestStepData.Id
                    };
                    return(targetStep);
                }

                return(step);
            }
コード例 #16
0
            private void HandleTestStepStartedMessage(TestStepStartedMessage message)
            {
                reportBox.Write(report =>
                {
                    ThrowIfDisposed();

                    if (message.Step.ParentId == null)
                    {
                        rootTestStepIds.Add(message.Step.Id);

                        if (!IsRootStarted)
                        {
                            StartRoot(report, message.Step);
                        }
                    }
                    else
                    {
                        TestStepData step = RedirectParentIdOfTestStepData(message.Step);
                        StartStep(report, step);
                    }
                });
            }
コード例 #17
0
        public void TestStepFinished_should_bubble_up_from_test_runner()
        {
            var progressMonitor      = MockProgressMonitor.Instance;
            var testRunnerExtensions = new BindingList <string>(new List <string>());

            optionsController.Stub(oc => oc.TestRunnerExtensions).Return(testRunnerExtensions);
            StubTestRunnerFactory();
            testController.Explore(progressMonitor, new List <string>());
            var testData     = new TestData("id", "name", "fullName");
            var testStepData = new TestStepData("id", "name", "fullName", "testId")
            {
                IsTestCase = true
            };
            var testStepRun = new TestStepRun(testStepData);
            var testStepFinishedEventArgs = new TestStepFinishedEventArgs(new Report(),
                                                                          testData, testStepRun);

            testRunnerEvents.Raise(tre => tre.TestStepFinished += null, testRunner,
                                   testStepFinishedEventArgs);

            eventAggregator.AssertWasCalled(ea => ea.Send(Arg.Is(testController), Arg <TestStepFinished> .Matches(tsf =>
                                                                                                                  tsf.TestData == testData && tsf.TestStepRun == testStepRun)));
        }
コード例 #18
0
ファイル: ModelAssert.cs プロジェクト: dougrathbone/mbunit-v3
        public static void AreEqual(TestStepData expected, TestStepData actual)
        {
            if (expected == null)
            {
                Assert.IsNull(actual);
                return;
            }

            AreEqual((TestComponentData)expected, actual);

            Assert.AreEqual(expected.FullName, actual.FullName);
            Assert.AreEqual(expected.ParentId, actual.ParentId);
            Assert.AreEqual(expected.TestId, actual.TestId);
            Assert.AreEqual(expected.IsPrimary, actual.IsPrimary);
            Assert.AreEqual(expected.IsTestCase, actual.IsTestCase);
            Assert.AreEqual(expected.IsDynamic, actual.IsDynamic);
        }
コード例 #19
0
        private string BeginStepContinuation(TestStepData step, Action action)
        {
            if (currentStepStack.Count == 0 || step.ParentId == currentStepStack.Peek())
            {
                currentStepStack.Push(step.Id);
                action();
                return step.Id;
            }

            SaveContinuation(SanitizeContinuationId(step.ParentId), () => BeginStepContinuation(step, action));
            return null;
        }
コード例 #20
0
 private TestStepRun CreateFakeTestStepRun(string id, bool isTestCase, TestOutcome outcome, params TestStepRun[] children)
 {
     var step = new TestStepData(id, "Name-" + id, "FullName-" + id, "Test-" + id);
     step.IsTestCase = isTestCase;
     var run = new TestStepRun(step);
     run.Result = new TestResult() { Outcome = outcome };
     run.Children.AddRange(children);
     return run;
 }
コード例 #21
0
            private void StartStep(Report report, TestStepData step)
            {
                TestData testData = GetTestData(report, step.TestId);
                TestStepRun testStepRun = new TestStepRun(step);
                testStepRun.StartTime = DateTime.Now;

                TestStepState parentState;
                if (step.ParentId != null)
                {
                    parentState = GetTestStepState(step.ParentId);
                    parentState.TestStepRun.Children.Add(testStepRun);
                }
                else
                {
                    parentState = null;
                    report.TestPackageRun.RootTestStepRun = testStepRun;
                }

                TestStepState state = new TestStepState(parentState, testData, testStepRun);
                states.Add(step.Id, state);

                eventDispatcher.NotifyTestStepStarted(
                    new TestStepStartedEventArgs(report, testData, testStepRun));
            }
コード例 #22
0
            private void StartRoot(Report report, TestStepData step)
            {
                rootTestStepData = step;

                StartStep(report, step);
            }
コード例 #23
0
 private void FinishRoot(Report report)
 {
     if (rootTestStepData != null)
     {
         rootTestStepResult.DurationInSeconds = rootTestStepStopwatch.Elapsed.TotalSeconds;
         FinishStep(report, rootTestStepData.Id, rootTestStepResult);
         rootTestStepData = null;
     }
 }
コード例 #24
0
        /// <summary>
        /// Builds the tree under the specified root test step run.
        /// </summary>
        /// <param name="root">The root test step run.</param>
        /// <returns></returns>
        public static TestStepRunNode BuildTreeFromRoot(TestStepRun root)
        {
            if (root == null)
            {
                var step = new TestStepData(String.Empty, String.Empty, String.Empty, String.Empty);
                root = new TestStepRun(step);
                root.Result = new TestResult();
            }

            int index = 0;
            var node = new TestStepRunNode(root, null, index++);
            node.Children.AddRange(GetChildren(node, ref index));
            return node;
        }
コード例 #25
0
        public void TestStepFinished_should_bubble_up_from_test_runner()
        {
            var progressMonitor = MockProgressMonitor.Instance;
            var testRunnerExtensions = new BindingList<string>(new List<string>());
            optionsController.Stub(oc => oc.TestRunnerExtensions).Return(testRunnerExtensions);
            StubTestRunnerFactory();
            testController.Explore(progressMonitor, new List<string>());
            var testData = new TestData("id", "name", "fullName");
            var testStepData = new TestStepData("id", "name", "fullName", "testId")
            {
                IsTestCase = true
            };
            var testStepRun = new TestStepRun(testStepData);
            var testStepFinishedEventArgs = new TestStepFinishedEventArgs(new Report(), 
                testData, testStepRun);

            testRunnerEvents.Raise(tre => tre.TestStepFinished += null, testRunner, 
                testStepFinishedEventArgs);

            eventAggregator.AssertWasCalled(ea => ea.Send(Arg.Is(testController), Arg<TestStepFinished>.Matches(tsf => 
                                                                                              tsf.TestData == testData && tsf.TestStepRun == testStepRun)));
        }
コード例 #26
0
 private void EndStep(TestStepData step, Action action)
 {
     string nextContinuationId = EndStepContinuation(step, action);
     ResumeContinuation(nextContinuationId);
 }
コード例 #27
0
        void CreateTestStepRun()
        {
            TestStepData testStepData = new TestStepData("a", "b", "c", "d");

            gallioTestStepRun = new TestStepRun(testStepData);
        }
コード例 #28
0
            private TestStepData RedirectParentIdOfTestStepData(TestStepData step)
            {
                if (step.ParentId != null && rootTestStepIds.Contains(step.ParentId))
                {
                    TestStepData targetStep = new TestStepData(step.Id, step.Name, step.FullName, step.TestId)
                    {
                        CodeLocation = step.CodeLocation,
                        CodeReference = step.CodeReference,
                        IsDynamic = step.IsDynamic,
                        IsPrimary = step.IsPrimary,
                        IsTestCase = step.IsTestCase,
                        Metadata = step.Metadata,
                        ParentId = rootTestStepData.Id
                    };
                    return targetStep;
                }

                return step;
            }
コード例 #29
0
        private string EndStepContinuation(TestStepData step, Action action)
        {
            if (step.Id == currentStepStack.Peek())
            {
                currentStepStack.Pop();
                action();
                return SanitizeContinuationId(step.ParentId);
            }

            SaveContinuation(step.Id, () => EndStepContinuation(step, action));
            return null;
        }
コード例 #30
0
        private void EndStep(TestStepData step, Action action)
        {
            string nextContinuationId = EndStepContinuation(step, action);

            ResumeContinuation(nextContinuationId);
        }
コード例 #31
0
        /// <inheritdoc />
        protected override void Initialize()
        {
            writer = new ServiceMessageWriter(output => Logger.Log(LogSeverity.Important, output));

            Events.InitializeStarted += delegate(object sender, InitializeStartedEventArgs e)
            {
                writer.WriteProgressMessage(flowId, "Initializing test runner.");
            };

            Events.ExploreStarted += delegate(object sender, ExploreStartedEventArgs e)
            {
                writer.WriteProgressStart(flowId, "Exploring tests.");
            };

            Events.ExploreFinished += delegate(object sender, ExploreFinishedEventArgs e)
            {
                writer.WriteProgressFinish(flowId, "Exploring tests."); // nb: message must be same as specified in progress start
            };

            Events.RunStarted += delegate(object sender, RunStartedEventArgs e)
            {
                writer.WriteProgressStart(flowId, "Running tests.");
            };

            Events.RunFinished += delegate(object sender, RunFinishedEventArgs e)
            {
                ClearStep();

                writer.WriteProgressFinish(flowId, "Running tests."); // nb: message must be same as specified in progress start
            };

            Events.DisposeFinished += delegate(object sender, DisposeFinishedEventArgs e)
            {
                writer.WriteProgressMessage(flowId, "Disposed test runner.");
            };

            Events.TestStepStarted += delegate(object sender, TestStepStartedEventArgs e)
            {
                TestStepData step = e.TestStepRun.Step;

                BeginStep(step, () =>
                {
                    string name = step.Name;
                    if (step.FullName.Length != 0 && name.Length != 0)
                    {
                        if (step.IsTestCase)
                        {
                            writer.WriteTestStarted(flowId, name, false);
                        }
                        else if (step.IsPrimary)
                        {
                            writer.WriteTestSuiteStarted(flowId, name);
                        }
                    }
                });
            };

            Events.TestStepFinished += delegate(object sender, TestStepFinishedEventArgs e)
            {
                TestStepRun  stepRun = e.TestStepRun;
                TestStepData step    = e.TestStepRun.Step;

                EndStep(step, () =>
                {
                    string name = step.Name;
                    if (step.FullName.Length != 0 && name.Length != 0)
                    {
                        if (step.IsTestCase)
                        {
                            TestOutcome outcome = stepRun.Result.Outcome;

                            var outputText  = new StringBuilder();
                            var errorText   = new StringBuilder();
                            var warningText = new StringBuilder();
                            var failureText = new StringBuilder();

                            foreach (StructuredStream stream in stepRun.TestLog.Streams)
                            {
                                switch (stream.Name)
                                {
                                default:
                                case MarkupStreamNames.ConsoleInput:
                                case MarkupStreamNames.ConsoleOutput:
                                case MarkupStreamNames.DebugTrace:
                                case MarkupStreamNames.Default:
                                    AppendWithSeparator(outputText, stream.ToString());
                                    break;

                                case MarkupStreamNames.ConsoleError:
                                    AppendWithSeparator(errorText, stream.ToString());
                                    break;

                                case MarkupStreamNames.Failures:
                                    AppendWithSeparator(failureText, stream.ToString());
                                    break;

                                case MarkupStreamNames.Warnings:
                                    AppendWithSeparator(warningText, stream.ToString());
                                    break;
                                }
                            }

                            if (outcome.Status != TestStatus.Skipped && warningText.Length != 0)
                            {
                                AppendWithSeparator(errorText, warningText.ToString());
                            }
                            if (outcome.Status != TestStatus.Failed && failureText.Length != 0)
                            {
                                AppendWithSeparator(errorText, failureText.ToString());
                            }

                            if (outputText.Length != 0)
                            {
                                writer.WriteTestStdOut(flowId, name, outputText.ToString());
                            }
                            if (errorText.Length != 0)
                            {
                                writer.WriteTestStdErr(flowId, name, errorText.ToString());
                            }

                            // TODO: Handle inconclusive.
                            if (outcome.Status == TestStatus.Failed)
                            {
                                writer.WriteTestFailed(flowId, name, outcome.ToString(), failureText.ToString());
                            }
                            else if (outcome.Status == TestStatus.Skipped)
                            {
                                writer.WriteTestIgnored(flowId, name, warningText.ToString());
                            }

                            writer.WriteTestFinished(flowId, name, stepRun.Result.Duration);
                        }
                        else if (step.IsPrimary)
                        {
                            writer.WriteTestSuiteFinished(flowId, name);
                        }
                    }
                });
            };
        }
コード例 #32
0
            private void StartRoot(Report report, TestStepData step)
            {
                rootTestStepData = step;

                StartStep(report, step);
            }