// 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);
        }
        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.PathExtension);

            return(actualLauncher.GetOutputOfCommand(workingDirectory, command, param, printTestOutput,
                                                     throwIfError, out processExitCode));
        }
        public void RunTests(IEnumerable <TestCase> testCasesToRun, bool isBeingDebugged,
                             IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            List <Thread> threads;

            lock (this)
            {
                threads = new List <Thread>();
                RunTests(testCasesToRun, threads, isBeingDebugged, debuggedLauncher, executor);
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }
        }
        private int LaunchProcessWithDebuggerAttached(string workingDirectory, IDictionary <string, string> envVars, string command, string param, bool printTestOutput,
                                                      IDebuggedProcessLauncher handle)
        {
            _logger.LogInfo(String.Format(Resources.AttachDebuggerMessage, command));
            if (printTestOutput)
            {
                _logger.DebugInfo(Resources.DebuggerAttachedOutputMessage);
            }
            _processId = handle.LaunchProcessWithDebuggerAttached(command, workingDirectory, envVars, param, _settings.GetPathExtension(command));
            Process process = Process.GetProcessById(_processId.Value);
            var     waiter  = new ProcessWaiter(process);

            waiter.WaitForExit();
            process.Dispose();
            return(waiter.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;
 }
Ejemplo n.º 8
0
        private int LaunchProcessWithDebuggerAttached(string workingDirectory, string command, string param, bool printTestOutput,
                                                      IDebuggedProcessLauncher handle)
        {
            _logger.LogInfo("Attaching debugger to " + command);
            if (printTestOutput)
            {
                _logger.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, _settings.GetPathExtension(command));
            Process process   = Process.GetProcessById(processId);
            var     waiter    = new ProcessWaiter(process);

            waiter.WaitForExit();
            process.Dispose();
            return(waiter.ProcessExitCode);
        }
        // ReSharper disable once UnusedParameter.Local
        private void RunTestsFromExecutable(string executable, string workingDir,
                                            IEnumerable <TestCase> testCasesToRun, string userParameters,
                                            bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            string resultXmlFile = Path.GetTempFileName();
            var    serializer    = new TestDurationSerializer();

            var generator = new CommandLineGenerator(testCasesToRun, executable.Length, userParameters, resultXmlFile, _settings);

            foreach (CommandLineGenerator.Args arguments in generator.GetCommandLines())
            {
                if (_canceled)
                {
                    break;
                }
                var streamingParser = new StreamingStandardOutputTestResultParser(arguments.TestCases, _logger, _frameworkReporter);
                var results         = RunTests(executable, workingDir, isBeingDebugged, debuggedLauncher, arguments, resultXmlFile, executor, streamingParser).ToArray();

                try
                {
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    _frameworkReporter.ReportTestsStarted(results.Select(tr => tr.TestCase));
                    _frameworkReporter.ReportTestResults(results);
                    stopwatch.Stop();
                    if (results.Length > 0)
                    {
                        _logger.DebugInfo($"{_threadName}Reported {results.Length} test results to VS, executable: '{executable}', duration: {stopwatch.Elapsed}");
                    }
                }
                catch (TestRunCanceledException e)
                {
                    _logger.DebugInfo($"{_threadName}Execution has been canceled: {e.InnerException?.Message ?? e.Message}");
                    Cancel();
                }

                serializer.UpdateTestDurations(results);
                foreach (TestResult result in results)
                {
                    if (!_schedulingAnalyzer.AddActualDuration(result.TestCase, (int)result.Duration.TotalMilliseconds))
                    {
                        _logger.DebugWarning("TestCase already in analyzer: " + result.TestCase.FullyQualifiedName);
                    }
                }
            }
        }
        public void RunTests(IEnumerable <TestCase> allTestCases, IEnumerable <TestCase> testCasesToRun, string baseDir,
                             string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher)
        {
            List <Thread> threads;

            lock (this)
            {
                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> 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 void RunTests(IEnumerable <TestCase> allTestCases, IEnumerable <TestCase> testCasesToRun, string baseDir,
                             string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher)
        {
            DebugUtils.AssertIsNull(userParameters, nameof(userParameters));

            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                string testDirectory = Utils.GetTempDirectory();
                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, 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);
            }
        }
Ejemplo n.º 16
0
        public void RunTests(IEnumerable <TestCase> testCasesToRun, string baseDir,
                             string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            DebugUtils.AssertIsNotNull(userParameters, nameof(userParameters));
            DebugUtils.AssertIsNotNull(workingDir, nameof(workingDir));

            IDictionary <string, List <TestCase> > groupedTestCases = testCasesToRun.GroupByExecutable();

            foreach (string executable in groupedTestCases.Keys)
            {
                string finalParameters = SettingsWrapper.ReplacePlaceholders(userParameters, executable);
                string finalWorkingDir = SettingsWrapper.ReplacePlaceholders(workingDir, executable);

                if (_canceled)
                {
                    break;
                }

                _settings.ExecuteWithSettingsForExecutable(executable, () =>
                {
                    var testsWithNoTestPropertySettings = groupedTestCases[executable];

                    if (_settings.TestPropertySettingsContainer != null)
                    {
                        testsWithNoTestPropertySettings = new List <TestCase>();

                        foreach (var testCase in groupedTestCases[executable])
                        {
                            ITestPropertySettings settings;
                            if (_settings.TestPropertySettingsContainer.TryGetSettings(testCase.FullyQualifiedName, out settings))
                            {
                                RunTestsFromExecutable(
                                    executable,
                                    settings.WorkingDirectory,
                                    settings.Environment,
                                    Enumerable.Repeat(testCase, 1),
                                    finalParameters,
                                    isBeingDebugged,
                                    debuggedLauncher,
                                    executor);
                            }
                            else
                            {
                                testsWithNoTestPropertySettings.Add(testCase);
                            }
                        }
                    }

                    if (testsWithNoTestPropertySettings.Count != 0)
                    {
                        RunTestsFromExecutable(
                            executable,
                            finalWorkingDir,
                            null,
                            testsWithNoTestPropertySettings,
                            finalParameters,
                            isBeingDebugged,
                            debuggedLauncher,
                            executor);
                    }
                }, _logger);
            }
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        public void RunTests(IEnumerable <TestCase> testCasesToRun, ITestFrameworkReporter reporter, IDebuggedProcessLauncher launcher, bool isBeingDebugged, string solutionDirectory, IProcessExecutor executor)
        {
            TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray();
            _logger.LogInfo(String.Format(Resources.NumberOfTestsRunningMessage, testCasesToRunAsArray.Length));

            lock (this)
            {
                if (_canceled)
                {
                    return;
                }
                ComputeTestRunner(reporter, isBeingDebugged, solutionDirectory);
            }

            _runner.RunTests(testCasesToRunAsArray, solutionDirectory, null, null, isBeingDebugged, launcher, executor);

            if (_settings.ParallelTestExecution)
            {
                _schedulingAnalyzer.PrintStatisticsToDebugOutput();
            }
        }
Ejemplo n.º 19
0
        public void RunTests(IEnumerable <TestCase> allTestCases, IEnumerable <TestCase> testCasesToRun, string baseDir,
                             string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            DebugUtils.AssertIsNull(userParameters, nameof(userParameters));
            DebugUtils.AssertIsNull(workingDir, nameof(workingDir));

            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                string testDirectory = Utils.GetTempDirectory();
                workingDir     = _settings.GetWorkingDir(_solutionDirectory, testDirectory, _threadId);
                userParameters = _settings.GetUserParameters(_solutionDirectory, testDirectory, _threadId);

                string batch = _settings.GetBatchForTestSetup(_solutionDirectory, testDirectory, _threadId);
                batch = batch == "" ? "" : _solutionDirectory + batch;
                SafeRunBatch(TestSetup, _solutionDirectory, batch, isBeingDebugged);

                _innerTestRunner.RunTests(allTestCases, testCasesToRun, baseDir, workingDir, userParameters, isBeingDebugged, debuggedLauncher, executor);

                batch = _settings.GetBatchForTestTeardown(_solutionDirectory, testDirectory, _threadId);
                batch = batch == "" ? "" : _solutionDirectory + batch;
                SafeRunBatch(TestTeardown, _solutionDirectory, batch, isBeingDebugged);

                stopwatch.Stop();
                _logger.DebugInfo($"{_threadName}Execution took {stopwatch.Elapsed}");

                string errorMessage;
                if (!Utils.DeleteDirectory(testDirectory, out errorMessage))
                {
                    _logger.DebugWarning(
                        $"{_threadName}Could not delete test directory '" + testDirectory + "': " + errorMessage);
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"{_threadName}Exception while running tests: " + e);
            }
        }
        private void RunTests(IEnumerable <TestCase> testCasesToRun, string baseDir, List <Thread> threads, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray();

            ITestsSplitter          splitter = GetTestsSplitter(testCasesToRunAsArray);
            List <List <TestCase> > splittedTestCasesToRun = splitter.SplitTestcases();

            _logger.LogInfo(string.Format(Resources.ThreadExecutionMessage, splittedTestCasesToRun.Count));
            _logger.DebugInfo(Resources.NoTestOutputShown);

            int threadId = 0;

            foreach (List <TestCase> testcases in splittedTestCasesToRun)
            {
                var runner = new PreparingTestRunner(threadId++, _solutionDirectory, _frameworkReporter, _logger, _settings.Clone(), _schedulingAnalyzer);
                _testRunners.Add(runner);

                var thread = new Thread(
                    () => runner.RunTests(testcases, baseDir, null, null, isBeingDebugged, debuggedLauncher, executor))
                {
                    Name = $"GTA Testrunner {threadId}"
                };
                threads.Add(thread);

                thread.Start();
            }
        }
        public void RunTests(IEnumerable <TestCase> testCasesToRun, string baseDir,
                             string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            DebugUtils.AssertIsNotNull(userParameters, nameof(userParameters));
            DebugUtils.AssertIsNotNull(workingDir, nameof(workingDir));

            IDictionary <string, List <TestCase> > groupedTestCases = testCasesToRun.GroupByExecutable();

            foreach (string executable in groupedTestCases.Keys)
            {
                string finalParameters = SettingsWrapper.ReplacePlaceholders(userParameters, executable);
                string finalWorkingDir = SettingsWrapper.ReplacePlaceholders(workingDir, executable);

                if (_canceled)
                {
                    break;
                }

                _settings.ExecuteWithSettingsForExecutable(executable, () =>
                {
                    RunTestsFromExecutable(
                        executable,
                        finalWorkingDir,
                        groupedTestCases[executable],
                        finalParameters,
                        isBeingDebugged,
                        debuggedLauncher,
                        executor);
                }, _logger);
            }
        }
        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)
 {
     return(GetOutputOfCommand(workingDirectory, null, command, param, printTestOutput, throwIfError, debuggedLauncher));
 }
        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)
            {
                ITestRunner runner = new PreparingTestRunner(threadId++, SolutionDirectory, FrameworkReporter, TestEnvironment);
                TestRunners.Add(runner);

                Thread thread = new Thread(() => runner.RunTests(allTestCases, testcases, baseDir, null, isBeingDebugged, debuggedLauncher));
                threads.Add(thread);

                thread.Start();
            }
        }
        public void RunTests(IEnumerable <TestCase> testCasesToRun, string baseDir,
                             string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            DebugUtils.AssertIsNull(userParameters, nameof(userParameters));
            DebugUtils.AssertIsNull(workingDir, nameof(workingDir));

            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                string testDirectory = Utils.GetTempDirectory();
                workingDir     = _settings.GetWorkingDir(_solutionDirectory, testDirectory, _threadId);
                userParameters = _settings.GetUserParameters(_solutionDirectory, testDirectory, _threadId);

                string batch = _settings.GetBatchForTestSetup(_solutionDirectory, testDirectory, _threadId);
                batch = batch == "" ? "" : _solutionDirectory + batch;
                SafeRunBatch(BatchType.TestSetup, _solutionDirectory, batch, isBeingDebugged);

                _innerTestRunner.RunTests(testCasesToRun, baseDir, workingDir, userParameters, isBeingDebugged, debuggedLauncher, executor);

                batch = _settings.GetBatchForTestTeardown(_solutionDirectory, testDirectory, _threadId);
                batch = batch == "" ? "" : _solutionDirectory + batch;
                SafeRunBatch(BatchType.TestTeardown, _solutionDirectory, batch, isBeingDebugged);

                stopwatch.Stop();
                _logger.DebugInfo(String.Format(Resources.ExecutionTime, _threadName, stopwatch.Elapsed));

                string errorMessage;
                if (!Utils.DeleteDirectory(testDirectory, out errorMessage))
                {
                    _logger.DebugWarning(String.Format(Resources.DeleteTestDir, _threadName, testDirectory, errorMessage));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(String.Format(Resources.ExceptionMessage, _threadName, e));
            }
        }
        public void RunTests(IEnumerable <TestCase> testCasesToRun, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            IDictionary <string, List <TestCase> > groupedTestCases = testCasesToRun.GroupByExecutable();

            foreach (string executable in groupedTestCases.Keys)
            {
                if (_canceled)
                {
                    break;
                }

                _settings.ExecuteWithSettingsForExecutable(executable, () =>
                {
                    string workingDir     = _settings.GetWorkingDirForExecution(executable, _testDir, _threadId);
                    string userParameters = _settings.GetUserParametersForExecution(executable, _testDir, _threadId);

                    RunTestsFromExecutable(
                        executable,
                        workingDir,
                        groupedTestCases[executable],
                        userParameters,
                        isBeingDebugged,
                        debuggedLauncher,
                        executor);
                }, _logger);
            }
        }
 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);
 }
        private void RunTests(IEnumerable <TestCase> testCasesToRun, List <Thread> threads, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
        {
            TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray();

            ITestsSplitter          splitter = GetTestsSplitter(testCasesToRunAsArray);
            List <List <TestCase> > splittedTestCasesToRun = splitter.SplitTestcases();

            _logger.LogInfo("Executing tests on " + splittedTestCasesToRun.Count + " threads");
            _logger.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++, _frameworkReporter, _logger, _settings.Clone(), _schedulingAnalyzer);
                _testRunners.Add(runner);

                var thread = new Thread(
                    () => runner.RunTests(testcases, isBeingDebugged, debuggedLauncher, executor))
                {
                    Name = $"GTA Testrunner {threadId}"
                };
                threads.Add(thread);

                thread.Start();
            }
        }
Ejemplo n.º 29
0
        public void RunTests(IEnumerable <TestCase> testCasesToRun, ITestFrameworkReporter reporter, IDebuggedProcessLauncher launcher, bool isBeingDebugged, IProcessExecutor executor)
        {
            TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray();
            _logger.LogInfo("Running " + testCasesToRunAsArray.Length + " tests...");

            lock (this)
            {
                if (_canceled)
                {
                    return;
                }
                ComputeTestRunner(reporter, isBeingDebugged);
            }

            _runner.RunTests(testCasesToRunAsArray, isBeingDebugged, launcher, executor);

            if (_settings.ParallelTestExecution)
            {
                _schedulingAnalyzer.PrintStatisticsToDebugOutput();
            }
        }