private static Test CreateAssemblyTest(IAssemblyInfo assembly, Version frameworkVersion) { MSTestAssembly assemblyTest = new MSTestAssembly(assembly.Name, assembly, frameworkVersion); assemblyTest.Kind = TestKinds.Assembly; ModelUtils.PopulateMetadataFromAssembly(assembly, assemblyTest.Metadata); return(assemblyTest); }
public TestOutcome RunSession(ITestContext assemblyTestContext, MSTestAssembly assemblyTest, ITestCommand assemblyTestCommand, TestStep parentTestStep, IProgressMonitor progressMonitor) { DirectoryInfo tempDir = SpecialPathPolicy.For("MSTestAdapter").CreateTempDirectoryWithUniqueName(); try { // Set the test results path. Among other things, the test results path // will determine where the deployed test files go. string testResultsPath = Path.Combine(tempDir.FullName, "tests.trx"); // Set the test results root directory. // This path determines both where MSTest searches for test files which // is used to resolve relative paths to test files in the "*.vsmdi" file. string searchPathRoot = Path.GetDirectoryName(assemblyTest.AssemblyFilePath); // Set the test metadata and run config paths. These are just temporary // files that can go anywhere on the filesystem. It happens to be convenient // to store them in the same temporary directory as the test results. string testMetadataPath = Path.Combine(tempDir.FullName, "tests.vsmdi"); string runConfigPath = Path.Combine(tempDir.FullName, "tests.runconfig"); progressMonitor.SetStatus("Generating test metadata file."); CreateTestMetadataFile(testMetadataPath, GetTestsFromCommands(assemblyTestCommand.PreOrderTraversal), assemblyTest.AssemblyFilePath); progressMonitor.SetStatus("Generating run config file."); CreateRunConfigFile(runConfigPath); progressMonitor.SetStatus("Executing tests."); Executor executor = new Executor(this, assemblyTestContext, assemblyTestCommand); TestOutcome outcome = executor.Execute(testMetadataPath, testResultsPath, runConfigPath, searchPathRoot); return outcome; } finally { try { tempDir.Delete(true); } catch { // Ignore I/O exceptions deleting temporary files. // They will probably be deleted by the OS later on during a file cleanup. } } }
private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor) { Test test = testCommand.Test; progressMonitor.SetStatus(test.Name); // The first test should be an assembly test MSTestAssembly assemblyTest = testCommand.Test as MSTestAssembly; TestOutcome outcome; TestResult result; if (assemblyTest != null) { ITestContext assemblyContext = testCommand.StartPrimaryChildStep(parentTestStep); try { MSTestRunner runner = MSTestRunner.GetRunnerForFrameworkVersion(frameworkVersion); outcome = runner.RunSession(assemblyContext, assemblyTest, testCommand, parentTestStep, progressMonitor); } catch (Exception ex) { assemblyContext.LogWriter.Failures.WriteException(ex, "Internal Error"); outcome = TestOutcome.Error; } result = assemblyContext.FinishStep(outcome, null); } else { result = new TestResult(TestOutcome.Skipped); } progressMonitor.Worked(1); return(result); }
private static Test CreateAssemblyTest(IAssemblyInfo assembly, Version frameworkVersion) { MSTestAssembly assemblyTest = new MSTestAssembly(assembly.Name, assembly, frameworkVersion); assemblyTest.Kind = TestKinds.Assembly; ModelUtils.PopulateMetadataFromAssembly(assembly, assemblyTest.Metadata); return assemblyTest; }