public TestExecutionResult ExecuteTests() { string vsFolder = _visualStudioFinder.Find(); vsFolder = Path.Combine(vsFolder, _appConfigDriver.VSTestPath); var vsTestConsoleExePath = Path.Combine(AssemblyFolderHelper.GetAssemblyFolder(), Environment.ExpandEnvironmentVariables(vsFolder + @"\vstest.console.exe")); var processHelper = new ProcessHelper(); string arguments = GenereateVsTestsArguments(); ProcessResult processResult; try { processResult = processHelper.RunProcess(_outputWriter, _testProjectFolders.ProjectFolder, vsTestConsoleExePath, arguments); } catch (Exception) { Console.WriteLine($"running vstest.console.exe failed - {_testProjectFolders.CompiledAssemblyPath} {vsTestConsoleExePath} {arguments}"); throw; } string output = processResult.CombinedOutput; var lines = output.SplitByString(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); var trxFiles = FindFilePath(lines, ".trx", BeginnOfTrxFileLine).ToArray(); var logFiles = FindFilePath(lines, ".log", BeginnOfLogFileLine).ToArray(); string logFileContent = logFiles.Length == 1 ? File.ReadAllText(_uriCleaner.ConvertSlashes(_uriCleaner.StripSchema(Uri.UnescapeDataString(logFiles.Single())))) : string.Empty; var reportFiles = GetReportFiles(output); trxFiles.Should().HaveCount(1, $"exactly one TRX file should be generated by VsTest;{Environment.NewLine}{string.Join(Environment.NewLine, trxFiles)}"); string trxFile = trxFiles.Single(); var testResultDocument = XDocument.Load(trxFile); LastTestExecutionResult = CalculateTestExecutionResultFromTrx(testResultDocument, _testRunConfiguration, output, reportFiles, logFileContent); return(LastTestExecutionResult); }
public TestExecutionResult ExecuteTests() { const string dotnetTestPath = "dotnet"; var envVariables = _testSuiteEnvironmentVariableGenerator.GenerateEnvironmentVariables(); var processHelper = new ProcessHelper(); string arguments = $"test {GenerateDotnetTestsArguments()}"; ProcessResult processResult; try { processResult = processHelper.RunProcess(_outputWriter, _testProjectFolders.PathToSolutionDirectory, dotnetTestPath, arguments, envVariables); } catch (Exception) { Console.WriteLine($"running {dotnetTestPath} failed - {_testProjectFolders.CompiledAssemblyPath} {dotnetTestPath} {arguments}"); throw; } string output = processResult.CombinedOutput; var lines = output.SplitByString(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); var trxFilePaths = FindFilePath(lines, ".trx", BeginOfTrxFileLine).ToArray(); var logFiles = FindFilePath(lines, ".log", BeginOfLogFileLine).ToArray(); string logFileContent = logFiles.Length == 1 ? File.ReadAllText(_uriCleaner.ConvertSlashes(_uriCleaner.StripSchema(Uri.UnescapeDataString(logFiles.Single())))) : string.Empty; var reportFiles = GetReportFiles(output); trxFilePaths.Should().HaveCountGreaterOrEqualTo(1, $"at least one TRX file should be generated by the test run; these have been generated:{Environment.NewLine}{string.Join(Environment.NewLine, trxFilePaths)}"); var trxFiles = from trxFilePath in trxFilePaths let trx = _trxParser.ParseTRXFile(trxFilePath, output, reportFiles, logFileContent) select(trxFilePath, trx); TestExecutionResultFiles = trxFiles.ToDictionary(trxFile => trxFile.trxFilePath, trxFile => trxFile.trx); LastTestExecutionResult = TestExecutionResultFiles.First(f => f.Key.Contains(_testProjectFolders.ProjectFolder)).Value; return(LastTestExecutionResult); }