private TestStepRun CreateFakeRun(string id, TestOutcome outcome, params TestStepRun[] children)
 {
     var run = new TestStepRun(new TestStepData(id, id, id, id));
     run.Result = new TestResult(outcome);
     run.Children.AddRange(children);
     return run;
 }
 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);
 }
        private ObjectModel.TestResult CreateTest(TestData test, TestStepRun stepRun, TestCase testCase)
        {
            ObjectModel.TestResult testResult = new ObjectModel.TestResult(testCase);
            testResult.DisplayName = test.Name;
            testResult.ErrorLineNumber = test.CodeLocation.Line;
            //testResult.ErrorStackTrace
            testResult.StartTime = stepRun.StartTime;
            if (stepRun.TestLog.Streams.Count > 0)
            {
                testResult.ErrorMessage = stepRun.TestLog.Streams[0].ToString();
            }
            testResult.EndTime = stepRun.EndTime;

            testResult.Duration = stepRun.Result.Duration;

            var testStatus = stepRun.Result.Outcome.Status;
            switch (testStatus)
            {
                case TestStatus.Passed:
                    testResult.Outcome = ObjectModel.TestOutcome.Passed;
                    break;
                case TestStatus.Failed:
                    testResult.Outcome = ObjectModel.TestOutcome.Failed;
                    break;
                case TestStatus.Skipped:
                    testResult.Outcome = ObjectModel.TestOutcome.Skipped;
                    break;
                case TestStatus.Inconclusive:
                    testResult.Outcome = ObjectModel.TestOutcome.NotFound;
                    break;
            }

            return testResult;
        }
        public void TestStepFinished_Test()
        {
            var testStepRun = new TestStepRun(new TestStepData("root", "name", "fullName", "root"))
              {
                  TestLog = new StructuredDocument()
              };
            testStepRun.TestLog.Attachments.Add(new TextAttachment("name", "contentType", "text").ToAttachmentData());
            
            var report = new Report
                {
                    TestPackageRun = new TestPackageRun(),
                    TestModel = new TestModelData()
                };
            report.TestPackageRun.RootTestStepRun = testStepRun;

            testController.Stub(x => x.ReadReport(null)).IgnoreArguments().Do((Action<ReadAction<Report>>)(action => action(report)));
            testTreeModel.Stub(x => x.Root).Return(new TestTreeNode("root", "root"));

            var flag = false;
            executionLogController.ExecutionLogUpdated += (sender, e) =>
            {
                Assert.Count(1, e.TestStepRuns);
                flag = true;
            };
            var testData = new TestData("root", "name", "fullName")
            {
                IsTestCase = true
            };

            executionLogController.Handle(new TestStepFinished(testData, null));

            Assert.IsTrue(flag);
        }
        private static GallioTestResult CreateTestResult(TestStepRun run, Guid runId, ITestElement test, bool includeTestStepRunXml)
        {
            var result = new GallioTestResult(runId, test);
            result.TestName = run.Step.FullName;
            result.Outcome = GetOutcome(run.Result.Outcome);

            foreach (StructuredStream stream in run.TestLog.Streams)
            {
                string contents = stream.ToString();

                if (stream.Name == MarkupStreamNames.DebugTrace)
                    result.DebugTrace += contents;
                else if (stream.Name == MarkupStreamNames.ConsoleOutput)
                    result.StdOut += contents;
                else if (stream.Name == MarkupStreamNames.ConsoleError)
                    result.StdErr += contents;
                else if (stream.Name == MarkupStreamNames.Failures || stream.Name == MarkupStreamNames.Warnings)
                    result.ErrorMessage += contents;
                else
                    result.DebugTrace += contents;
            }

            result.SetTimings(run.StartTime, run.EndTime, run.Result.Duration);

            if (includeTestStepRunXml)
                result.TestStepRunXml = TestStepRunToXml(run);

            foreach (TestStepRun childRun in run.Children)
                result.AddInnerResult(CreateTestResult(childRun, runId, test, false));

            return result;
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <param name="lifecyclePhase">The lifecycle phase name.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// <paramref name="testStepRun"/>, or <paramref name="lifecyclePhase"/> is null.</exception>
        public TestStepLifecyclePhaseChangedEventArgs(Report report, TestData test, TestStepRun testStepRun, string lifecyclePhase)
            : base(report, test, testStepRun)
        {
            if (lifecyclePhase == null)
                throw new ArgumentNullException("lifecyclePhase");

            this.lifecyclePhase = lifecyclePhase;
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <param name="logStreamName">The log stream name.</param>
        /// <param name="sectionName">The name of the section that was started.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// <paramref name="testStepRun"/>, <paramref name="logStreamName"/>, or <paramref name="sectionName"/> is null.</exception>
        public TestStepLogStreamBeginSectionBlockEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName, string sectionName)
            : base(report, test, testStepRun, logStreamName)
        {
            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            this.sectionName = sectionName;
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <param name="attachment">The attachment.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// <paramref name="testStepRun"/> or <paramref name="attachment"/> is null.</exception>
        public TestStepLogAttachEventArgs(Report report, TestData test, TestStepRun testStepRun, Attachment attachment)
            : base(report, test, testStepRun)
        {
            if (attachment == null)
                throw new ArgumentNullException("attachment");

            this.attachment = attachment;
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <param name="logStreamName">The log stream name.</param>
        /// <param name="text">The text that was written.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// <paramref name="testStepRun"/> or <paramref name="logStreamName"/> is null.</exception>
        public TestStepLogStreamWriteEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName, string text)
            : base(report, test, testStepRun, logStreamName)
        {
            if (text == null)
                throw new ArgumentNullException("text");

            this.text = text;
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <param name="logStreamName">The log stream name.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// <paramref name="testStepRun"/> or <paramref name="logStreamName"/> is null.</exception>
        protected TestStepLogStreamEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName)
            : base(report, test, testStepRun)
        {
            if (logStreamName == null)
                throw new ArgumentNullException("logStreamName");

            this.logStreamName = logStreamName;
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <param name="logStreamName">The log stream name.</param>
        /// <param name="attachmentName">The name of the attachment that was embedded.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// <paramref name="testStepRun"/>, <paramref name="logStreamName"/>, or <paramref name="attachmentName"/> is null.</exception>
        public TestStepLogStreamEmbedEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName, string attachmentName)
            : base(report, test, testStepRun, logStreamName)
        {
            if (attachmentName == null)
                throw new ArgumentNullException("attachmentName");

            this.attachmentName = attachmentName;
        }
        public void TestInstanceRuns()
        {
            TestStepRun testStepRun = new TestStepRun(new TestStepData("stepId", "stepName", "stepFullName", "testId"));
            testStepRun.Children.Add(new TestStepRun(new TestStepData("stepId", "stepName", "stepFullName", "testId")));
            testPackageRun.RootTestStepRun = testStepRun;

            Assert.AreElementsEqual(new TestStepRun[] { testStepRun, testStepRun.Children[0] },
                testPackageRun.AllTestStepRuns);
        }
 private static TestStepFinished GetTestStepFinished(TestStatus testStatus)
 {
     var testStepRun = new TestStepRun(new TestStepData("id", "name", "fullName", "testId"))
     {
         Step = new TestStepData("id", "name", "fullName", "testId") { IsTestCase = true },
         Result = new TestResult(new TestOutcome(testStatus))
     };
     return new TestStepFinished(null, testStepRun);
 }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <param name="metadataKey">The metadata key.</param>
        /// <param name="metadataValue">The metadata value.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// <paramref name="testStepRun"/>, <paramref name="metadataKey"/> or <paramref name="metadataValue" /> is null.</exception>
        public TestStepMetadataAddedEventArgs(Report report, TestData test, TestStepRun testStepRun, string metadataKey, string metadataValue)
            : base(report, test, testStepRun)
        {
            if (metadataKey == null)
                throw new ArgumentNullException("metadataKey");
            if (metadataValue == null)
                throw new ArgumentNullException("metadataValue");

            this.metadataKey = metadataKey;
            this.metadataValue = metadataValue;
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="test">The test data.</param>
        /// <param name="testStepRun">The test step run.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
        /// or <paramref name="testStepRun"/> is null.</exception>
        protected TestStepEventArgs(Report report, TestData test, TestStepRun testStepRun)
        {
            if (report == null)
                throw new ArgumentNullException("report");
            if (test == null)
                throw new ArgumentNullException("test");
            if (testStepRun == null)
                throw new ArgumentNullException("testStepRun");

            this.report = report;
            this.test = test;
            this.testStepRun = testStepRun;
        }
        public TestResult BuildTestResult(TestData testData, TestStepRun testStepRun, TestCase testCase)
        {
            var testResult = new TestResult(testCase)
            {
                DisplayName = testData.Name,
                StartTime = testStepRun.StartTime,
                EndTime = testStepRun.EndTime,
                Duration = testStepRun.Result.Duration,
                Outcome = GetOutcome(testStepRun.Result.Outcome.Status),
            };

            var failuresStream = testStepRun.TestLog.GetStream(MarkupStreamNames.Failures);
            if (failuresStream != null)
            {
                testResult.ErrorMessage = failuresStream.ToString();
                failuresStream.Body.AcceptContents(new StackTraceHunter(s => testResult.ErrorStackTrace = s));
            }

            return testResult;
        }
        public void MergeStepStatistics(TestStatus status, bool isTestCase)
        {
            TestStepRun testStepRun = new TestStepRun(new TestStepData("stepId", "stepName", "fullName", "testId"));
            testStepRun.Result.Outcome = new TestOutcome(status);
            testStepRun.Result.AssertCount = 3;
            testStepRun.Step.IsTestCase = isTestCase;

            stats.MergeStepStatistics(testStepRun);
            Assert.AreEqual(3, stats.AssertCount);
            Assert.AreEqual(1, stats.StepCount);
            Assert.AreEqual(isTestCase ? 1 : 0, stats.TestCount);
            Assert.AreEqual(isTestCase && status != TestStatus.Skipped ? 1 : 0, stats.RunCount);

            Assert.AreEqual(isTestCase && status == TestStatus.Skipped ? 1 : 0, stats.SkippedCount);
            Assert.AreEqual(isTestCase && status == TestStatus.Passed ? 1 : 0, stats.PassedCount);
            Assert.AreEqual(isTestCase && status == TestStatus.Inconclusive ? 1 : 0, stats.InconclusiveCount);
            Assert.AreEqual(isTestCase && status == TestStatus.Failed ? 1 : 0, stats.FailedCount);

            Assert.AreEqual(isTestCase ? 1 : 0, stats.GetOutcomeCount(new TestOutcome(status)));
        }
Example #18
0
        /// <summary>
        /// Merges statistics from a test step run, incrementing the relevant counters.
        /// </summary>
        /// <param name="testStepRun">The test step run.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testStepRun"/> is null.</exception>
        public void MergeStepStatistics(TestStepRun testStepRun)
        {
            if (testStepRun == null)
            {
                throw new ArgumentNullException("testStepRun");
            }

            // The assert count and duration statistics are pre-aggregated in that parent tests include
            // the values for their children when publishing their results.  This implies that the
            // root test will contain the official final tally which will be larger than all previously
            // seen tallies.
            assertCount = Math.Max(assertCount, testStepRun.Result.AssertCount);
            duration    = Math.Max(duration, testStepRun.Result.DurationInSeconds);

            stepCount += 1;

            if (!testStepRun.Step.IsTestCase)
            {
                return;
            }

            testCount += 1;
            AddOutcome(testStepRun.Result.Outcome);
        }
 /// <summary>
 /// Returns the log of the specified test step run.
 /// </summary>
 /// <param name="run">The test step run.</param>
 /// <returns>The log text or an empty string.</returns>
 protected static string GetLog(TestStepRun run)
 {
     return GetLog(run, MarkupStreamNames.Default);
 }
 /// <summary>
 /// Initializes the event arguments.
 /// </summary>
 /// <param name="report">The report.</param>
 /// <param name="test">The test data.</param>
 /// <param name="testStepRun">The test step run.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
 /// or <paramref name="testStepRun"/> is null.</exception>
 public TestStepFinishedEventArgs(Report report, TestData test, TestStepRun testStepRun)
     : base(report, test, testStepRun)
 {
 }
 /// <summary>
 /// Returns the log of the specified test step run.
 /// </summary>
 /// <param name="run">The test step run.</param>
 /// <param name="streamName">The name of log stream.</param>
 /// <returns>The log text or an empty string.</returns>
 protected static string GetLog(TestStepRun run, string streamName)
 {
     StructuredStream stream = run.TestLog.GetStream(streamName);
     return (stream == null) ? String.Empty : stream.ToString();
 }
Example #22
0
 private static IEnumerable <TestStepRun> GetChildren(TestStepRun node)
 {
     return(node.Children);
 }
                public TestStepState(TestStepState parent, TestData testData, TestStepRun testStepRun)
                {
                    Parent = parent;
                    TestData = testData;
                    TestStepRun = testStepRun;

                    LogWriter = new StructuredDocumentWriter();
                    testStepRun.TestLog = LogWriter.Document;
                }
 /// <summary>
 /// Initializes the event arguments.
 /// </summary>
 /// <param name="report">The report.</param>
 /// <param name="test">The test data.</param>
 /// <param name="testStepRun">The test step run.</param>
 /// <param name="logStreamName">The log stream name.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
 /// <paramref name="testStepRun"/> or <paramref name="logStreamName"/> is null.</exception>
 public TestStepLogStreamEndBlockEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName)
     : base(report, test, testStepRun, logStreamName)
 {
 }
 public TestStepFinished(TestData testData, TestStepRun testStepRun)
 {
     TestData = testData;
     TestStepRun = testStepRun;
 }
Example #26
0
 private static string FormatStream(TestStepRun testStepRun, string streamName)
 {
     StructuredStream stream = testStepRun.TestLog.GetStream(streamName);
     return stream != null ? stream.ToString() : @"";
 }
Example #27
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;
        }
Example #28
0
 private static IEnumerable<TestStepRun> GetChildren(TestStepRun node)
 {
     return node.Children;
 }
 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;
 }
 /// <summary>
 /// Initializes the event arguments.
 /// </summary>
 /// <param name="report">The report.</param>
 /// <param name="test">The test data.</param>
 /// <param name="testStepRun">The test step run.</param>
 /// <param name="logStreamName">The log stream name.</param>
 /// <param name="marker">The marker.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/>
 /// <paramref name="testStepRun"/> or <paramref name="logStreamName"/> is null.</exception>
 public TestStepLogStreamBeginMarkerBlockEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName, Marker marker)
     : base(report, test, testStepRun, logStreamName)
 {
     this.marker = marker;
 }
        public void ExecutionLog_should_be_updated_when_test_selection_changes()
        {
            var testStepRun = new TestStepRun(new TestStepData("rootStep", "name", 
                "fullName", "root"));
            var selectedTests = new List<TestTreeNode>
                {
                    new TestTreeNode("name", "rootStep")
                };
            var report = new Report
                {
                    TestPackageRun = new TestPackageRun(),
                    TestModel = new TestModelData()
                };
            report.TestPackageRun.RootTestStepRun = testStepRun;

            testController.Stub(x => x.ReadReport(Arg<ReadAction<Report>>.Is.Anything))
                .Do((Action<ReadAction<Report>>)(action => action(report)));
            testTreeModel.Stub(x => x.Root).Return(new TestTreeNode("root", "name"));
            var flag = false;
            executionLogController.ExecutionLogUpdated += delegate { flag = true; };

            executionLogController.Handle(new TestSelectionChanged(selectedTests));

            Assert.IsTrue(flag);
        }
Example #32
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="run">The test step run.</param>
        /// <param name="parent">The parent node.</param>
        /// <param name="index">The zero-based index of the test step run in the sequential representation of the tree.</param>
        public TestStepRunNode(TestStepRun run, TestStepRunNode parent, int index)
        {
            if (run == null)
                throw new ArgumentNullException("run");

            this.run = run;
            this.parent = parent;
            this.index = index;
        }