Exemple #1
0
        public void ExecuteShouldNotFillInDebugAndTraceLogsFromRunningTestMethod()
        {
            StringWriter writer         = new StringWriter(new StringBuilder());
            var          testMethodInfo = new TestableTestmethodInfo(
                this.methodInfo,
                this.testClassInfo,
                this.testMethodOptions,
                () =>
            {
                writer.Write("InTestMethod");
                return(new UTF.TestResult()
                {
                    Outcome = UTF.UnitTestOutcome.Passed
                });
            });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, true);

            this.testablePlatformServiceProvider.MockTraceListener.Setup(tl => tl.GetWriter()).Returns(writer);

            var results = testMethodRunner.Execute();

            Assert.AreEqual(string.Empty, results[0].DebugTrace);
        }
Exemple #2
0
        public void RunTestMethodShouldSetParentResultOutcomeProperlyForDataSourceDataDrivenTests()
        {
            var testExecutedCount = 0;
            var testMethodInfo    = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () =>
            {
                return((testExecutedCount++ == 0) ?
                       new UTF.TestResult {
                    Outcome = UTF.UnitTestOutcome.Failed
                } :
                       new UTF.TestResult {
                    Outcome = UTF.UnitTestOutcome.Passed
                });
            });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            UTF.DataSourceAttribute dataSourceAttribute = new UTF.DataSourceAttribute("DummyConnectionString", "DummyTableName");

            var attribs = new Attribute[] { dataSourceAttribute };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);
            this.testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.GetData(testMethodInfo, this.testContextImplementation)).Returns(new object[] { 1, 2, 3 });

            var results = testMethodRunner.RunTestMethod();

            // check for parent result
            Assert.AreEqual(4, results.Length);
            Assert.AreEqual(results[0].ExecutionId, results[1].ParentExecId);
            Assert.AreEqual(Guid.Empty, results[0].ParentExecId);
            Assert.AreNotEqual(Guid.Empty, results[1].ParentExecId);

            // Check for aggregate outcome.
            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Failed, results[1].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Passed, results[2].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Passed, results[3].Outcome);
        }
Exemple #3
0
        public void RunTestMethodShouldReturnParentResultForDataRowDataDrivenTests()
        {
            UTF.TestResult testResult = new UTF.TestResult
            {
                ResultFiles = new List <string>()
                {
                    "C:\\temp.txt"
                }
            };

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int dummyIntData1 = 1;
            int dummyIntData2 = 2;

            UTF.DataRowAttribute dataRowAttribute1 = new UTF.DataRowAttribute(dummyIntData1);
            UTF.DataRowAttribute dataRowAttribute2 = new UTF.DataRowAttribute(dummyIntData2);

            var attribs = new Attribute[] { dataRowAttribute1, dataRowAttribute2 };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            CollectionAssert.Contains(results[1].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(results[2].ResultFiles.ToList(), "C:\\temp.txt");

            // Parent result should exist.
            Assert.AreEqual(3, results.Length);
            Assert.AreEqual(results[0].ExecutionId, results[1].ParentExecId);
            Assert.AreEqual(results[0].ExecutionId, results[2].ParentExecId);
            Assert.AreEqual(Guid.Empty, results[0].ParentExecId);
            Assert.AreNotEqual(Guid.Empty, results[1].ParentExecId);
            Assert.AreNotEqual(Guid.Empty, results[2].ParentExecId);
        }
        public void RunTestMethodShouldFillInDisplayNameWithDataRowDisplayNameIfProvidedForDataDrivenTests()
        {
            UTF.TestResult testResult       = new UTF.TestResult();
            var            testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
            var            testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int    dummyIntData    = 2;
            string dummyStringData = "DummyString";

            UTF.DataRowAttribute dataRowAttribute = new UTF.DataRowAttribute(dummyIntData, dummyStringData)
            {
                DisplayName = "DataRowTestDisplayName"
            };

            var attribs = new Attribute[] { dataRowAttribute };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(ro => ro.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            Assert.AreEqual(1, results.Length);
            Assert.AreEqual("DataRowTestDisplayName", results[0].DisplayName);
        }
        public void ExecuteShouldFillInLogsIfAssemblyInitializeThrows()
        {
            StringWriter writer = new StringWriter(new StringBuilder());

            DummyTestClass.AssemblyInitializeMethodBody = (UTFExtension.TestContext tc) =>
            {
                writer.Write("Hills");
                tc.WriteLine("Valleys");
                throw new ArgumentException();
            };
            this.testClassInfo.Parent.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("DummyAssemblyInit");
            var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult()
            {
                Outcome = UTF.UnitTestOutcome.Passed
            });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, true);

            this.testablePlatformServiceProvider.MockTraceListener.Setup(tl => tl.GetWriter()).Returns(writer);

            var results = testMethodRunner.Execute();

            Assert.AreEqual("Hills", results[0].DebugTrace);
            StringAssert.Contains(results[0].TestContextMessages, "Valleys");
        }
Exemple #6
0
        public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataRowAttribute()
        {
            UTF.TestResult testResult = new UTF.TestResult();
            testResult.Outcome = UTF.UnitTestOutcome.Inconclusive;

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int    dummyIntData    = 2;
            string dummyStringData = "DummyString";

            UTF.DataRowAttribute dataRowAttribute = new UTF.DataRowAttribute(
                dummyIntData,
                dummyStringData);

            var attribs = new Attribute[] { dataRowAttribute };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(ro => ro.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            Assert.AreEqual(AdapterTestOutcome.Inconclusive, results[0].Outcome);
        }