// ReSharper disable once UnusedParameter.Local private void RunTestsFromExecutable(string executable, string workingDir, IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher) { string resultXmlFile = Path.GetTempFileName(); var serializer = new TestDurationSerializer(); var generator = new CommandLineGenerator(allTestCases, testCasesToRun, executable.Length, userParameters, resultXmlFile, _testEnvironment); foreach (CommandLineGenerator.Args arguments in generator.GetCommandLines()) { if (_canceled) { break; } _frameworkReporter.ReportTestsStarted(arguments.TestCases); List<string> consoleOutput = new TestProcessLauncher(_testEnvironment, isBeingDebugged).GetOutputOfCommand(workingDir, executable, arguments.CommandLine, _testEnvironment.Options.PrintTestOutput && !_testEnvironment.Options.ParallelTestExecution, false, debuggedLauncher); IEnumerable<TestResult> results = CollectTestResults(arguments.TestCases, resultXmlFile, consoleOutput, baseDir); Stopwatch stopwatch = Stopwatch.StartNew(); _frameworkReporter.ReportTestResults(results); stopwatch.Stop(); _testEnvironment.DebugInfo($"Reported {results.Count()} test results to VS, executable: '{executable}', duration: {stopwatch.Elapsed}"); serializer.UpdateTestDurations(results); } }
public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher) { DebugUtils.AssertIsNotNull(userParameters, nameof(userParameters)); DebugUtils.AssertIsNotNull(workingDir, nameof(workingDir)); IDictionary<string, List<TestCase>> groupedTestCases = testCasesToRun.GroupByExecutable(); TestCase[] allTestCasesAsArray = allTestCases as TestCase[] ?? allTestCases.ToArray(); foreach (string executable in groupedTestCases.Keys) { string finalParameters = SettingsWrapper.ReplacePlaceholders(userParameters, executable); string finalWorkingDir = SettingsWrapper.ReplacePlaceholders(workingDir, executable); if (_canceled) break; RunTestsFromExecutable( executable, finalWorkingDir, allTestCasesAsArray.Where(tc => tc.Source == executable), groupedTestCases[executable], baseDir, finalParameters, isBeingDebugged, debuggedLauncher); } }
public List<string> GetOutputOfCommand(string workingDirectory, string command, string param, bool printTestOutput, bool throwIfError, IDebuggedProcessLauncher debuggedLauncher, out int processExitCode) { if (_isBeingDebugged) { var output = new List<string>(); processExitCode = LaunchProcessWithDebuggerAttached(workingDirectory, command, param, printTestOutput, debuggedLauncher); return output; } var actualLauncher = new ProcessLauncher(_testEnvironment, _testEnvironment.Options.GetPathExtension(command)); return actualLauncher.GetOutputOfCommand(workingDirectory, command, param, printTestOutput, throwIfError, out processExitCode); }
private int LaunchProcessWithDebuggerAttached(string workingDirectory, string command, string param, bool printTestOutput, IDebuggedProcessLauncher handle) { _testEnvironment.LogInfo("Attaching debugger to " + command); if (printTestOutput) { _testEnvironment.DebugInfo( "Note that due to restrictions of the VS Unit Testing framework, the test executable's output can not be displayed in the test console when debugging tests!"); } int processId = handle.LaunchProcessWithDebuggerAttached(command, workingDirectory, param, _testEnvironment.Options.GetPathExtension(command)); Process process = Process.GetProcessById(processId); var waiter = new ProcessWaiter(process); waiter.WaitForExit(); process.Dispose(); return waiter.ProcessExitCode; }
public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher) { List<Thread> threads; lock (this) { DebugUtils.AssertIsNull(workingDir, nameof(workingDir)); DebugUtils.AssertIsNull(userParameters, nameof(userParameters)); threads = new List<Thread>(); RunTests(allTestCases, testCasesToRun, baseDir, threads, isBeingDebugged, debuggedLauncher); } foreach (Thread thread in threads) { thread.Join(); } }
public void RunTests(IEnumerable<TestCase> allTestCasesInExecutables, IEnumerable<TestCase> testCasesToRun, ITestFrameworkReporter reporter, IDebuggedProcessLauncher launcher, bool isBeingDebugged, string solutionDirectory) { _testEnvironment.DebugInfo(_testEnvironment.Options.ToString()); TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray(); _testEnvironment.LogInfo("Running " + testCasesToRunAsArray.Length + " tests..."); lock (this) { if (_canceled) { return; } ComputeTestRunner(reporter, isBeingDebugged, solutionDirectory); } _runner.RunTests(allTestCasesInExecutables, testCasesToRunAsArray, solutionDirectory, null, null, isBeingDebugged, launcher); }
private void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, List<Thread> threads, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher) { TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray(); ITestsSplitter splitter = GetTestsSplitter(testCasesToRunAsArray); List<List<TestCase>> splittedTestCasesToRun = splitter.SplitTestcases(); _testEnvironment.LogInfo("Executing tests on " + splittedTestCasesToRun.Count + " threads"); _testEnvironment.DebugInfo("Note that no test output will be shown on the test console when executing tests concurrently!"); int threadId = 0; foreach (List<TestCase> testcases in splittedTestCasesToRun) { var runner = new PreparingTestRunner(threadId++, _solutionDirectory, _frameworkReporter, _testEnvironment); _testRunners.Add(runner); var thread = new Thread(() => runner.RunTests(allTestCases, testcases, baseDir, null, null, isBeingDebugged, debuggedLauncher)); threads.Add(thread); thread.Start(); } }
public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher) { DebugUtils.AssertIsNull(userParameters, nameof(userParameters)); DebugUtils.AssertIsNull(workingDir, nameof(workingDir)); try { Stopwatch stopwatch = Stopwatch.StartNew(); string testDirectory = Utils.GetTempDirectory(); workingDir = _testEnvironment.Options.GetWorkingDir(_solutionDirectory, testDirectory, _threadId); userParameters = _testEnvironment.Options.GetUserParameters(_solutionDirectory, testDirectory, _threadId); string batch = _testEnvironment.Options.GetBatchForTestSetup(_solutionDirectory, testDirectory, _threadId); batch = batch == "" ? "" : _solutionDirectory + batch; SafeRunBatch(TestSetup, _solutionDirectory, batch, isBeingDebugged); _innerTestRunner.RunTests(allTestCases, testCasesToRun, baseDir, workingDir, userParameters, isBeingDebugged, debuggedLauncher); batch = _testEnvironment.Options.GetBatchForTestTeardown(_solutionDirectory, testDirectory, _threadId); batch = batch == "" ? "" : _solutionDirectory + batch; SafeRunBatch(TestTeardown, _solutionDirectory, batch, isBeingDebugged); stopwatch.Stop(); _testEnvironment.DebugInfo($"Thread {_threadId} took {stopwatch.Elapsed}"); string errorMessage; if (!Utils.DeleteDirectory(testDirectory, out errorMessage)) { _testEnvironment.DebugWarning( "Could not delete test directory '" + testDirectory + "': " + errorMessage); } } catch (Exception e) { _testEnvironment.LogError("Exception while running tests: " + e); } }
public List<string> GetOutputOfCommand(string workingDirectory, string command, string param, bool printTestOutput, bool throwIfError, IDebuggedProcessLauncher debuggedLauncher) { int dummy; return GetOutputOfCommand(workingDirectory, command, param, printTestOutput, throwIfError, debuggedLauncher, out dummy); }