public void RunTestMethodForPassingTestThrowingExceptionShouldReturnUnitTestResultWithPassedOutcome() { 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); }
public TestMethodRunnerTests() { var constructorInfo = typeof(DummyTestClass).GetConstructors().Single(); this.methodInfo = typeof(DummyTestClass).GetMethods().Single(m => m.Name.Equals("DummyTestMethod")); var classAttribute = new UTF.TestClassAttribute(); this.testMethodAttribute = new UTF.TestMethodAttribute(); var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext"); var testAssemblyInfo = new TestAssemblyInfo(); this.testMethod = new TestMethod("dummyTestName", "dummyClassName", "dummyAssemblyName", false); this.testContextImplementation = new TestContextImplementation(this.testMethod, new StringWriter(), new Dictionary <string, object>()); this.testClassInfo = new TestClassInfo( type: typeof(DummyTestClass), constructor: constructorInfo, testContextProperty: testContextProperty, classAttribute: classAttribute, parent: testAssemblyInfo); this.globaltestMethodOptions = new TestMethodOptions() { Timeout = 3600 * 1000, Executor = this.testMethodAttribute, TestContext = this.testContextImplementation, ExpectedException = null }; var globalTestMethodInfo = new TestMethodInfo( this.methodInfo, this.testClassInfo, this.globaltestMethodOptions); var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, null); this.globalTestMethodRunner = new TestMethodRunner(globalTestMethodInfo, this.testMethod, this.testContextImplementation, false); this.testMethodOptions = new TestMethodOptions() { Timeout = 200, Executor = this.testMethodAttribute, TestContext = this.testContextImplementation, ExpectedException = null }; this.mockReflectHelper = new Mock <ReflectHelper>(); // Reset test hooks DummyTestClass.TestConstructorMethodBody = () => { }; DummyTestClass.TestContextSetterBody = value => { }; DummyTestClass.TestInitializeMethodBody = value => { }; DummyTestClass.TestMethodBody = instance => { }; DummyTestClass.TestCleanupMethodBody = value => { }; }
public void RunTestMethodShouldGiveTestResultAsFailedWhenTestMethodFails() { 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.RunTestMethod(); // Since data is not provided, tests run normally giving passed as outcome. Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome); }
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); }
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); }
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); }
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"); }
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); }
public void RunTestMethodShouldSetDataRowIndexForDataDrivenTestsWhenDataIsProvidedUsingDataSourceAttribute() { var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult()); 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 datarowIndex Assert.AreEqual(0, results[0].DatarowIndex); Assert.AreEqual(1, results[1].DatarowIndex); Assert.AreEqual(2, results[2].DatarowIndex); }
public void RunTestMethodShouldSetParentResultOutcomeProperlyForDataRowDataDrivenTests() { 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, 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(); // 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); // 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); }
public void RunTestMethodShouldReturnParentResultForDataSourceDataDrivenTestsContainingSingleTest() { var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult()); 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 }); var results = testMethodRunner.RunTestMethod(); // Parent result should exist. Assert.AreEqual(2, results.Length); Assert.AreEqual(results[0].ExecutionId, results[1].ParentExecId); Assert.AreEqual(Guid.Empty, results[0].ParentExecId); Assert.AreNotEqual(Guid.Empty, results[1].ParentExecId); }
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); }
public void RunTestMethodShouldFillInDisplayNameWithDataRowArgumentsIfNoDisplayNameIsProvidedForDataDrivenTests() { 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); var attribs = new Attribute[] { dataRowAttribute }; // Setup mocks this.testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs); var results = testMethodRunner.RunTestMethod(); Assert.AreEqual(results[0].DisplayName, "DummyTestMethod (2,DummyString)"); }
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); }
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); }
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 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); }