Esempio n. 1
0
        public void ExecuteForClassInitializeThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome()
        {
            // Arrange.
            var tai = new TestAssemblyInfo(typeof(DummyTestClass).Assembly);

            var constructorInfo     = typeof(DummyTestClass).GetConstructors().Single();
            var classAttribute      = new UTF.TestClassAttribute();
            var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext");

            var tci = new TestClassInfo(
                type: typeof(DummyTestClass),
                constructor: constructorInfo,
                testContextProperty: testContextProperty,
                classAttribute: classAttribute,
                parent: tai)
            {
                ClassInitializeMethod = typeof(TestMethodRunnerTests).GetMethod(
                    "InitMethodThrowingException",
                    BindingFlags.Static | BindingFlags.NonPublic)
            };

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, tci, this.testMethodOptions, () => { throw new Exception("DummyException"); });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            // Act.
            var results = testMethodRunner.Execute();

            // Assert.
            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
            StringAssert.Contains(results[0].ErrorMessage, "System.ArgumentException: Value does not fall within the expected range.");
        }
Esempio n. 2
0
        public void RunTestMethodForMultipleResultsReturnMultipleResults()
        {
            var testMethodAttributeMock = new Mock <UTF.TestMethodAttribute>();

            testMethodAttributeMock.Setup(_ => _.Execute(It.IsAny <UTF.ITestMethod>())).Returns(new[]
            {
                new UTF.TestResult {
                    Outcome = UTF.UnitTestOutcome.Passed
                },
                new UTF.TestResult {
                    Outcome = UTF.UnitTestOutcome.Failed
                }
            });

            var localTestMethodOptions = new TestMethodOptions
            {
                Timeout           = 200,
                Executor          = testMethodAttributeMock.Object,
                TestContext       = this.testContextImplementation,
                ExpectedException = null
            };

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, localTestMethodOptions, null);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            var results = testMethodRunner.Execute();

            Assert.AreEqual(2, results.Length);

            Assert.AreEqual(AdapterTestOutcome.Passed, results[0].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Failed, results[1].Outcome);
        }
Esempio n. 3
0
        public void ExecuteForTestThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome()
        {
            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => { throw new Exception("DummyException"); });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            var results = testMethodRunner.Execute();

            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
            StringAssert.Contains(results[0].ErrorMessage, "Exception thrown while executing test");
        }
Esempio n. 4
0
        public void RunTestMethodForFailingTestThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome()
        {
            var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult()
            {
                Outcome = UTF.UnitTestOutcome.Failed
            });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            var results = testMethodRunner.Execute();

            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
        }
Esempio n. 5
0
        public void ExecuteForPassingTestShouldReturnUnitTestResultWithPassedOutcome()
        {
            var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, 200, this.testMethodAttribute, this.testClassInfo, this.testContextImplementation, () => new UTF.TestResult()
            {
                Outcome = UTF.UnitTestOutcome.Passed
            });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            var results = testMethodRunner.Execute();

            Assert.AreEqual(AdapterTestOutcome.Passed, results[0].Outcome);
        }
Esempio n. 6
0
        public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodButHasNoMessage()
        {
            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, null);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.IsAttributeDefined(typeof(DummyTestClass), typeof(UTF.IgnoreAttribute), It.IsAny <bool>())).Returns(false);
            this.mockReflectHelper.Setup(rh => rh.IsAttributeDefined(this.methodInfo, typeof(UTF.IgnoreAttribute), It.IsAny <bool>())).Returns(true);
            this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(this.methodInfo)).Returns(string.Empty);

            var results = testMethodRunner.Execute();

            Assert.AreEqual(AdapterTestOutcome.Ignored, results[0].Outcome);
            Assert.AreEqual(string.Empty, results[0].ErrorMessage);
        }
Esempio n. 7
0
        public void RunTestMethodChecksIfTestsAreDataDriven()
        {
            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, false);

            // setup mocks
            this.testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.HasDataDrivenTests(testMethodInfo));
            var results = testMethodRunner.Execute();

            // Since data is not provided, tests run normally giving passed as outcome.
            Assert.AreEqual(AdapterTestOutcome.Passed, results[0].Outcome);
        }
Esempio n. 8
0
        public void ExecuteShouldNotFillInDebugAndTraceLogsIfDebugTraceDisabled()
        {
            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, false);

            StringWriter writer = new StringWriter(new StringBuilder("DummyTrace"));

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

            var results = testMethodRunner.Execute();

            Assert.AreEqual(results[0].DebugTrace, string.Empty);
        }
Esempio n. 9
0
        public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethod()
        {
            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, null);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.IsAttributeDefined(typeof(DummyTestClass), typeof(UTF.IgnoreAttribute), It.IsAny <bool>())).Returns(true);
            this.mockReflectHelper.Setup(rh => rh.IsAttributeDefined(this.methodInfo, typeof(UTF.IgnoreAttribute), It.IsAny <bool>())).Returns(true);

            this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(typeof(DummyTestClass).GetTypeInfo())).Returns("IgnoreTestClassMessage");
            this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(this.methodInfo)).Returns("IgnoreMethodMessage");

            var results = testMethodRunner.Execute();

            Assert.AreEqual(results[0].Outcome, AdapterTestOutcome.Ignored);
            Assert.AreEqual(results[0].ErrorMessage, "IgnoreTestClassMessage");
        }
Esempio n. 10
0
        public void RunTestMethodRunsDataDrivenTestsWhenDataIsProvided()
        {
            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult());
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            // Set outcome to be failed
            var result = new UTF.TestResult();

            result.Outcome = UTF.UnitTestOutcome.Failed;

            // setup mocks
            this.testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.HasDataDrivenTests(It.IsAny <TestMethodInfo>())).Returns(true);
            this.testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.RunDataDrivenTest(It.IsAny <UTFExtension.TestContext>(), It.IsAny <TestMethodInfo>(), It.IsAny <TestMethod>(), It.IsAny <UTF.TestMethodAttribute>()))
            .Returns(new UTF.TestResult[] { result });

            var results = testMethodRunner.Execute();

            // check for outcome
            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
        }
Esempio n. 11
0
        public void ExecuteShouldFillInDebugAndTraceLogsFromAssemblyInitialize()
        {
            StringWriter writer = new StringWriter(new StringBuilder());

            DummyTestClass.AssemblyInitializeMethodBody = (UTFExtension.TestContext tc) =>
            {
                writer.Write("AssemblyInit trace");
            };
            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("AssemblyInit trace", results[0].DebugTrace);
        }
Esempio n. 12
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);
        }