public void RunTestMethodShouldSetResultFilesIfPresentForDataDrivenTests() { 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[0].ResultFiles.ToList(), "C:\\temp.txt"); CollectionAssert.Contains(results[1].ResultFiles.ToList(), "C:\\temp.txt"); }
public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataRowAttribute() { UTF.TestResult testResult = new UTF.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); }
public void RunTestMethodShouldReturnParentResultForDataRowDataDrivenTestsContainingSingleTest() { 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; UTF.DataRowAttribute dataRowAttribute1 = new UTF.DataRowAttribute(dummyIntData1); var attribs = new Attribute[] { dataRowAttribute1 }; // 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"); // 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 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(); // 1st results should be parent result. Assert.AreEqual(2, results.Length); Assert.AreEqual("DataRowTestDisplayName", results[1].DisplayName); }
public void RunDataDrivenTestsShouldAttachResultsFilesForEachTestCase() { this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties); TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new TestFrameworkV2.DataSourceAttribute( "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential); this.mockTestMethodInfo.Setup(ds => ds.GetAttributes <TestFrameworkV2.DataSourceAttribute>(false)) .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute }); TestFrameworkV2.TestResult testResult = new TestFrameworkV2.TestResult(); DummyTestClass testClassInstance = new DummyTestClass(); var methodInfo = typeof(DummyTestClass).GetMethod("PassingTest"); this.mockTestMethodInfo.Setup(ds => ds.Invoke(null)). Callback(() => { try { testClassInstance.TestContext = this.testContextImplementation; var task = methodInfo.Invoke(testClassInstance, null) as Task; task?.GetAwaiter().GetResult(); testResult.Outcome = TestFrameworkV2.UnitTestOutcome.Passed; testResult.ResultFiles = this.testContextImplementation.GetResultFiles(); } catch (Exception ex) { testResult.Outcome = TestFrameworkV2.UnitTestOutcome.Failed; testResult.TestFailureException = ex; } }).Returns(testResult); this.mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo); TestFrameworkV2.TestMethodAttribute testMethodAttribute = new TestFrameworkV2.TestMethodAttribute(); TestDataSource testDataSource = new TestDataSource(); TestFrameworkV2.TestResult[] result = testDataSource.RunDataDrivenTest(this.testContextImplementation, this.mockTestMethodInfo.Object, null, testMethodAttribute); CollectionAssert.Contains(result[0].ResultFiles.ToList(), "C:\\temp.txt"); CollectionAssert.Contains(result[1].ResultFiles.ToList(), "C:\\temp.txt"); CollectionAssert.Contains(result[2].ResultFiles.ToList(), "C:\\temp.txt"); CollectionAssert.Contains(result[3].ResultFiles.ToList(), "C:\\temp.txt"); }
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); }