public void AutoEmbedScreenshot(string testName, bool triggered)
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(typeof(RecordingSample), testName);

            if (Capture.CanCaptureScreenshot())
            {
                if (triggered)
                {
                    Assert.Count(1, run.TestLog.Attachments);
                    Assert.AreEqual(MimeTypes.FlashVideo, run.TestLog.Attachments[0].ContentType);
                }
                else
                {
                    Assert.Count(0, run.TestLog.Attachments);
                }
            }
            else
            {
                if (triggered)
                {
                    Assert.Contains(run.TestLog.ToString(), "Recording not available.");
                }
                else
                {
                    Assert.DoesNotContain(run.TestLog.ToString(), "Recording not available.");
                }
            }
        }
        public void CapturesConsoleError()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(ConsoleAndDebugTraceSample).GetMethod("ConsoleError")));

            AssertLogContains(run, "Hello", MarkupStreamNames.ConsoleOutput); // xUnit consolidates error and output
            //AssertLogContains(run, "Hello", MarkupStreamNames.ConsoleError);
        }
Exemplo n.º 3
0
        public void NoThreadAbortsBubbledUpToTheFixture()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(TasksSample)));

            Assert.AreEqual(TestOutcome.Passed, run.Result.Outcome);
            Assert.AreEqual("", run.TestLog.ToString());
        }
Exemplo n.º 4
0
        public void StaticRun()
        {
            TestData fixtureData = Runner.GetTestData(CodeReference.CreateFromType(typeof(StaticSample)));

            Assert.Count(1, fixtureData.Children);

            TestData testData = fixtureData.Children[0];

            Assert.AreEqual("Test", testData.Name);
            Assert.IsTrue(testData.IsTestCase);
            Assert.AreEqual("System.Int32", testData.CodeReference.TypeName);
            Assert.AreEqual("Me", testData.Metadata.GetValue(MetadataKeys.AuthorName));
            Assert.AreEqual(TestKinds.Test, testData.Metadata.GetValue(MetadataKeys.TestKind));
            Assert.Count(0, testData.Children);

            TestStepRun fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(StaticSample)));

            Assert.Count(1, fixtureRun.Children);

            TestStepRun testRun = fixtureRun.Children[0];

            Assert.AreEqual("Test", testRun.Step.Name);
            Assert.IsFalse(testRun.Step.IsDynamic);
            Assert.IsTrue(testRun.Step.IsPrimary);
            Assert.IsTrue(testRun.Step.IsTestCase);
            Assert.AreEqual("System.Int32", testRun.Step.CodeReference.TypeName);
            Assert.AreEqual("Me", testRun.Step.Metadata.GetValue(MetadataKeys.AuthorName));
            Assert.AreEqual(TestKinds.Test, testRun.Step.Metadata.GetValue(MetadataKeys.TestKind));
            Assert.AreEqual("*** Log ***\n\nSetup->Execute->TearDown\n", testRun.TestLog.ToString());
            Assert.Count(0, testRun.Children);
        }
Exemplo n.º 5
0
        public void Pythagoras()
        {
            TestStepRun theoryRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DataDrivenTest).GetMethod("Pythagoras")));

            Assert.AreEqual("Pythagoras", theoryRun.Step.Name);
            Assert.AreEqual(TestOutcome.Failed, theoryRun.Result.Outcome);
            Assert.IsTrue(theoryRun.Step.IsPrimary);
            Assert.IsFalse(theoryRun.Step.IsDynamic);
            Assert.Count(3, theoryRun.Children);

            TestStepRun run1 = theoryRun.Children[0]; // 3, 4, 5

            Assert.AreEqual("Pythagoras", run1.Step.Name);
            Assert.IsFalse(run1.Step.IsPrimary);
            Assert.IsTrue(run1.Step.IsDynamic);
            Assert.AreEqual(TestOutcome.Passed, run1.Result.Outcome);

            TestStepRun run2 = theoryRun.Children[1]; // 6, 8, 10

            Assert.AreEqual("Pythagoras", run2.Step.Name);
            Assert.IsFalse(run2.Step.IsPrimary);
            Assert.IsTrue(run2.Step.IsDynamic);
            Assert.AreEqual(TestOutcome.Passed, run2.Result.Outcome);

            TestStepRun run3 = theoryRun.Children[2]; // 1, 1, 1

            Assert.AreEqual("Pythagoras", run3.Step.Name);
            Assert.IsFalse(run3.Step.IsPrimary);
            Assert.IsTrue(run3.Step.IsDynamic);
            Assert.AreEqual(TestOutcome.Failed, run3.Result.Outcome);
        }
Exemplo n.º 6
0
        public void RunTestRepeatedly()
        {
            TestStepRun testRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(RepeatTestSample).GetMethod("Test")));

            AssertLogContains(testRun, "3 of 4 repetitions passed.");
            Assert.AreEqual(TestOutcome.Failed, testRun.Result.Outcome);

            IList <TestStepRun> testSteps = testRun.Children;

            Assert.Count(4, testSteps, "Expected 4 repetitions represented as steps.");

            Assert.AreEqual("Repetition #1", testSteps[0].Step.Name);
            AssertLogContains(testSteps[0], "Run: Repetition #1");
            Assert.AreEqual(TestOutcome.Passed, testSteps[0].Result.Outcome);

            Assert.AreEqual("Repetition #2", testSteps[1].Step.Name);
            AssertLogContains(testSteps[1], "Run: Repetition #2");
            AssertLogContains(testSteps[1], "Boom", MarkupStreamNames.Failures);
            Assert.AreEqual(TestOutcome.Failed, testSteps[1].Result.Outcome);

            Assert.AreEqual("Repetition #3", testSteps[2].Step.Name);
            AssertLogContains(testSteps[2], "Run: Repetition #3");
            Assert.AreEqual(TestOutcome.Passed, testSteps[2].Result.Outcome);

            Assert.AreEqual("Repetition #4", testSteps[3].Step.Name);
            AssertLogContains(testSteps[3], "Run: Repetition #4");
            Assert.AreEqual(TestOutcome.Passed, testSteps[3].Result.Outcome);
        }
Exemplo n.º 7
0
        public void SelectedExplicitTestWillNotRunAndWillNotAppearInTheReport()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(
                CodeReference.CreateFromMember(typeof(ExplicitSample).GetMethod("UnselectedExplicitTest")));

            Assert.IsNull(run);
        }
Exemplo n.º 8
0
        public void AutoEmbedRecording_EmbedsVideoWhenTriggered(string testName, bool triggered)
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(AutoEmbedRecordingSamples).GetMethod(testName)));

            if (Capture.CanCaptureScreenshot())
            {
                if (triggered)
                {
                    Assert.Count(1, run.TestLog.Attachments);
                    Assert.AreEqual(MimeTypes.FlashVideo, run.TestLog.Attachments[0].ContentType);
                }
                else
                {
                    Assert.Count(0, run.TestLog.Attachments);
                }
            }
            else
            {
                if (triggered)
                {
                    Assert.Contains(run.TestLog.ToString(), "Recording not available.");
                }
                else
                {
                    Assert.DoesNotContain(run.TestLog.ToString(), "Recording not available.");
                }
            }
        }
Exemplo n.º 9
0
        public void PassTestPassed()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(SimpleTest).GetMethod("Pass")));

            Assert.IsNotNull(run);
            Assert.AreEqual(TestStatus.Passed, run.Result.Outcome.Status);
        }
Exemplo n.º 10
0
 private bool RelevantStep(TestStepRun testStepRun)
 {
     // only update log if the test is selected in the tree or,
     // if no tests are selected, if it is the root.
     return(selectedTestIds.Contains(testStepRun.Step.TestId) ||
            (selectedTestIds.Count == 0 && testStepRun.Step.TestId == testTreeModel.Root.Id));
 }
Exemplo n.º 11
0
        public void DefaultApartmentStateMayBeSetOnPerAssemblyBasis()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(
                                                               typeof(AssemblyApartmentStateSample).GetMethod("WriteApartmentStateToLog")));

            Assert.Contains(run.TestLog.ToString(), "MTA");
        }
Exemplo n.º 12
0
        public void TestStepFinished_TestCase_Ignored([Column(true, false)] bool primary)
        {
            var report      = new Report();
            var testData    = new TestData("id", "testName", "testFullName");
            var testStepRun = new TestStepRun(new TestStepData("stepId", "stepName", "stepFullName", "id")
            {
                IsPrimary = primary, IsTestCase = true
            })
            {
                Result = new TestResult()
                {
                    Outcome = TestOutcome.Ignored, DurationInSeconds = 0.3
                },
                TestLog = ComprehensiveDocument
            };

            dispatcher.NotifyTestStepStarted(new TestStepStartedEventArgs(report, testData, testStepRun));
            log.Clear();

            dispatcher.NotifyTestStepFinished(new TestStepFinishedEventArgs(report, testData, testStepRun));

            Assert.AreEqual("##teamcity[testStdOut name='stepName' out='output|n|ninput|n|ntrace|n|nlog' flowId='flow']\n"
                            + "##teamcity[testStdErr name='stepName' out='error|n|nfailure' flowId='flow']\n"
                            + "##teamcity[testIgnored name='stepName' message='warning' flowId='flow']\n"
                            + "##teamcity[testFinished name='stepName' duration='300' flowId='flow']\n", log.ToString());
        }
Exemplo n.º 13
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));
            }
Exemplo n.º 14
0
        public void RunFixtureRepeatedly()
        {
            TestStepRun fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(ThreadedRepeatFixtureSample)));

            AssertLogContains(fixtureRun, "9 of 10 threaded repetitions passed.");
            Assert.AreEqual(TestOutcome.Failed, fixtureRun.Result.Outcome);

            IList <TestStepRun> fixtureSteps = fixtureRun.Children;

            Assert.Count(10, fixtureSteps, "Expected 10 repetitions represented as steps.");

            for (int i = 0; i < 10; i++)
            {
                string      name        = "Threaded Repetition #" + (i + 1);
                TestStepRun fixtureStep = GenericCollectionUtils.Find(fixtureSteps, candidate => candidate.Step.Name == name);
                Assert.Count(1, fixtureStep.Children);

                TestStepRun testRun = fixtureStep.Children[0];
                AssertLogContains(testRun, "Run: " + name);

                if (i == 1)
                {
                    Assert.AreEqual(TestOutcome.Failed, fixtureStep.Result.Outcome);
                    Assert.AreEqual(TestOutcome.Failed, testRun.Result.Outcome);
                    AssertLogContains(testRun, "Boom", MarkupStreamNames.Failures);
                }
                else
                {
                    Assert.AreEqual(TestOutcome.Passed, fixtureStep.Result.Outcome);
                    Assert.AreEqual(TestOutcome.Passed, testRun.Result.Outcome);
                }
            }
        }
        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);
        }
Exemplo n.º 16
0
        public void FailTestFailed()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(SimpleTest).GetMethod("Fail")));

            Assert.AreEqual(TestOutcome.Failed, run.Result.Outcome);
            Assert.Contains(run.TestLog.GetStream(MarkupStreamNames.Failures).ToString(), "Boom");
        }
Exemplo n.º 17
0
        public void VerifySampleOutput(string sampleName, string expectedOutput)
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(BinaryDataSample).GetMethod(sampleName)));

            Assert.Count(1, run.Children, "Different number of runs than expected.");
            AssertLogContains(run.Children[0], expectedOutput);
        }
Exemplo n.º 18
0
            private void RenderExecutionLogStreams(TestStepRun testStepRun, bool flashEnabled)
            {
                writer.Write("<div id=\"log-");
                WriteHtmlEncoded(writer, testStepRun.Step.Id);
                writer.Write("\" class=\"log\">");

                foreach (StructuredStream executionLogStream in testStepRun.TestLog.Streams)
                {
                    writer.Write("<div class=\"logStream logStream-");
                    WriteHtmlEncoded(writer, executionLogStream.Name);
                    writer.Write("\">");
                    writer.Write("<span class=\"logStreamHeading\"><xsl:value-of select=\"");
                    WriteHtmlEncoded(writer, executionLogStream.Name);
                    writer.Write("\" /></span>");
                    writer.Write("<div class=\"logStreamBody\">");

                    executionLogStream.Body.Accept(new RenderTagVisitor(formatter, writer, testStepRun, flashEnabled));

                    writer.Write("</div></div>");
                }

                if (testStepRun.TestLog.Attachments.Count > 0)
                {
                    RenderExecutionLogAttachmentList(testStepRun);
                }

                writer.Write("</div>");
            }
Exemplo n.º 19
0
 public RenderTagVisitor(HtmlTestStepRunFormatter formatter, TextWriter writer, TestStepRun testStepRun, bool flashEnabled)
 {
     this.formatter    = formatter;
     this.writer       = writer;
     this.testStepRun  = testStepRun;
     this.flashEnabled = flashEnabled;
 }
Exemplo n.º 20
0
        /// <summary>
        /// Gets the test step runs associated with a test result.
        /// </summary>
        public static IList <TestStepRun> GetTestStepRuns(GallioTestResult result)
        {
            List <TestStepRun> runs = new List <TestStepRun>();

            if (result.IsAggregateRoot)
            {
                foreach (GallioTestResult innerResult in result.InnerResults)
                {
                    TestStepRun run = GetTestStepRun(innerResult);
                    if (run != null)
                    {
                        runs.Add(run);
                    }
                }
            }
            else
            {
                TestStepRun run = GetTestStepRun(result);
                if (run != null)
                {
                    runs.Add(run);
                }
            }

            return(runs);
        }
Exemplo n.º 21
0
 private void SaveAttachments(TestStepRun stepRun)
 {
     foreach (AttachmentData attachmentData in stepRun.TestLog.Attachments)
     {
         SaveAttachment(stepRun.Step.Id, attachmentData);
     }
 }
Exemplo n.º 22
0
        public void ApplicationBaseIsSameAsDirectoryContainingTestAssembly()
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(
                CodeReference.CreateFromMember(typeof(WorkingDirectoryAndApplicationBaseSample).GetMethod("ApplicationBaseIsSameAsDirectoryContainingTestAssembly")));

            Assert.AreEqual(TestOutcome.Passed, run.Result.Outcome);
        }
Exemplo n.º 23
0
        public void Pythagoras()
        {
            TestStepRun theoryRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(TheorySample).GetMethod("Pythagoras")));

            Assert.AreEqual("Pythagoras", theoryRun.Step.Name);
            Assert.AreEqual(TestOutcome.Failed, theoryRun.Result.Outcome);
            Assert.IsTrue(theoryRun.Step.IsPrimary);
            Assert.IsFalse(theoryRun.Step.IsDynamic);
            Assert.AreEqual(3, theoryRun.Children.Count);

            TestStepRun run1 = (from x in theoryRun.Children where x.Step.Name.Contains("a: 3, b: 4, c: 5") select x).Single();

            Assert.AreEqual("Pythagoras(a: 3, b: 4, c: 5)", run1.Step.Name);
            Assert.IsFalse(run1.Step.IsPrimary);
            Assert.IsTrue(run1.Step.IsDynamic);
            Assert.AreEqual(TestOutcome.Passed, run1.Result.Outcome);

            TestStepRun run2 = (from x in theoryRun.Children where x.Step.Name.Contains("a: 6, b: 8, c: 10") select x).Single();

            Assert.AreEqual("Pythagoras(a: 6, b: 8, c: 10)", run2.Step.Name);
            Assert.IsFalse(run2.Step.IsPrimary);
            Assert.IsTrue(run2.Step.IsDynamic);
            Assert.AreEqual(TestOutcome.Passed, run2.Result.Outcome);

            TestStepRun run3 = (from x in theoryRun.Children where x.Step.Name.Contains("a: 1, b: 1, c: 1") select x).Single();

            Assert.AreEqual("Pythagoras(a: 1, b: 1, c: 1)", run3.Step.Name);
            Assert.IsFalse(run3.Step.IsPrimary);
            Assert.IsTrue(run3.Step.IsDynamic);
            Assert.AreEqual(TestOutcome.Failed, run3.Result.Outcome);
        }
Exemplo n.º 24
0
 public void Visit(TestStepRun testStepRun)
 {
     foreach (StructuredStream stream in testStepRun.TestLog.Streams)
     {
         VisitBodyTag(stream.Body);
     }
 }
Exemplo n.º 25
0
        public void StaticRun()
        {
            TestData fixtureTest = Runner.GetTestData(CodeReference.CreateFromType(typeof(StaticSample)));

            Assert.Count(1, fixtureTest.Children);

            TestData referenceData = fixtureTest.Children[0];

            Assert.AreEqual("ReferencedFixture", referenceData.Name);
            Assert.IsFalse(referenceData.IsTestCase);
            Assert.Count(1, referenceData.Children);

            TestData testData = referenceData.Children[0];

            Assert.AreEqual("Test", testData.Name);

            TestStepRun fixtureRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromType(typeof(StaticSample)));

            Assert.Count(1, fixtureRun.Children);

            TestStepRun suiteRun = fixtureRun.Children[0];

            Assert.AreEqual("ReferencedFixture", suiteRun.Step.Name);
            Assert.IsFalse(suiteRun.Step.IsDynamic);
            Assert.IsTrue(suiteRun.Step.IsPrimary);
            Assert.IsFalse(suiteRun.Step.IsTestCase);
            Assert.AreEqual("", suiteRun.TestLog.ToString());
            Assert.Count(1, suiteRun.Children);

            TestStepRun testRun = suiteRun.Children[0];

            Assert.AreEqual("Test", testRun.Step.Name);
            Assert.AreEqual("*** Log ***\n\nExecute\n", testRun.TestLog.ToString());
        }
Exemplo n.º 26
0
        public void DependentTestsSkippedIfTheirTransitiveDependenciesFail()
        {
            TestStepRun test5Run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(DependsOnSample).GetMethod("Test5_DependsOnTest3_Skipped")));

            Assert.Contains(test5Run.TestLog.ToString(), "Skipped due to an unsatisfied test dependency.");
            Assert.DoesNotContain(test5Run.TestLog.ToString(), "Run");
            Assert.AreEqual(TestOutcome.Skipped, test5Run.Result.Outcome);
        }
Exemplo n.º 27
0
        private static string TestStepRunToXml(TestStepRun run)
        {
            StringWriter  stringWriter = new StringWriter();
            XmlSerializer serializer   = new XmlSerializer(typeof(TestStepRun));

            serializer.Serialize(stringWriter, run);
            return(stringWriter.ToString());
        }
Exemplo n.º 28
0
        public void RunDataDrivenTests(string fullName, string[] expectedTestLogOutput)
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(r => r.Step.FullName.EndsWith(fullName));

            Assert.AreElementsEqualIgnoringOrder(expectedTestLogOutput,
                                                 run.Children.Select(x => x.TestLog.GetStream(MarkupStreamNames.Default).ToString()),
                                                 (x, y) => y.Contains(x));
        }
Exemplo n.º 29
0
        public void Run()
        {
            TestStepRun testRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(NonConvertibleStubSample).GetMethod("Test")));

            Assert.AreEqual(TestOutcome.Passed, testRun.Result.Outcome);
            AssertLogContains(testRun, "CustomConverter: source = 123");
            AssertLogContains(testRun, "CustomConverter: source = 456");
        }
Exemplo n.º 30
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);
        }