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(typeof(DummyTestClass).Assembly); 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 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 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, null, new Dictionary <string, object>()); this.testClassInfo = new TestClassInfo( type: typeof(DummyTestClass), constructor: constructorInfo, testContextProperty: testContextProperty, classAttribute: classAttribute, parent: testAssemblyInfo); var globalTestMethodInfo = new TestMethodInfo( this.methodInfo, timeout: 3600 * 1000, executor: this.testMethodAttribute, expectedException: null, parent: this.testClassInfo, testContext: this.testContextImplementation); this.globalTestMethodRunner = new TestMethodRunner(globalTestMethodInfo, this.testMethod, this.testContextImplementation, false); // Reset test hooks DummyTestClass.TestConstructorMethodBody = () => { }; DummyTestClass.TestContextSetterBody = value => { }; DummyTestClass.TestInitializeMethodBody = value => { }; DummyTestClass.TestMethodBody = instance => { }; DummyTestClass.TestCleanupMethodBody = value => { }; }
internal TestableTestmethodInfo(MethodInfo testMethod, int timeout, UTF.TestMethodAttribute executor, TestClassInfo parent, TestContextImplementation testContext, Func <UTF.TestResult> invoke) : base(testMethod, timeout, executor, null, parent, testContext) { this.invokeTest = invoke; }