private ITestsSplitter GetTestsSplitter(TestCase[] testCasesToRun) { var serializer = new TestDurationSerializer(); IDictionary <TestCase, int> durations = serializer.ReadTestDurations(testCasesToRun); foreach (KeyValuePair <TestCase, int> duration in durations) { if (!_schedulingAnalyzer.AddExpectedDuration(duration.Key, duration.Value)) { _logger.DebugWarning("TestCase already in analyzer: " + duration.Key.FullyQualifiedName); } } ITestsSplitter splitter; if (durations.Count < testCasesToRun.Length) { splitter = new NumberBasedTestsSplitter(testCasesToRun, _settings); _logger.DebugInfo("Using splitter based on number of tests"); } else { splitter = new DurationBasedTestsSplitter(durations, _settings); _logger.DebugInfo("Using splitter based on test durations"); } return(splitter); }
private void AssertDurationsFileIsCreated(bool parallelExecution) { string sampleTestsDurationsFile = TestResources.SampleTests + GoogleTestConstants.DurationsExtension; RemoveFileIfNecessary(sampleTestsDurationsFile); string crashingTestsDurationsFile = TestResources.HardCrashingSampleTests + GoogleTestConstants.DurationsExtension; RemoveFileIfNecessary(crashingTestsDurationsFile); MockOptions.Setup(o => o.ParallelTestExecution).Returns(parallelExecution); MockOptions.Setup(o => o.MaxNrOfThreads).Returns(2); var processExecutor = new ProcessExecutor(null, TestEnvironment.Logger); var collectingReporter = new FakeFrameworkReporter(); var testExecutor = new GoogleTestExecutor(TestEnvironment.Logger, TestEnvironment.Options); testExecutor.RunTests(TestDataCreator.AllTestCasesExceptLoadTests, TestDataCreator.AllTestCasesExceptLoadTests, collectingReporter, null, false, TestResources.SampleTestsSolutionDir, processExecutor); sampleTestsDurationsFile.AsFileInfo() .Should() .Exist("Test execution should result in test durations"); var durations = new TestDurationSerializer().ReadTestDurations(TestDataCreator.AllTestCasesOfSampleTests); durations.Keys.Should().Contain( TestDataCreator.AllTestCasesOfSampleTests.Where(tc => collectingReporter.ReportedTestResults.Any(tr => tc.Equals(tr.TestCase) && (tr.Outcome == TestOutcome.Passed || tr.Outcome == TestOutcome.Failed)))); crashingTestsDurationsFile.AsFileInfo() .Should() .Exist("Test execution should result in test durations file"); durations = new TestDurationSerializer().ReadTestDurations(TestDataCreator.AllTestCasesOfHardCrashingTests); durations.Keys.Should().Contain(TestDataCreator.AllTestCasesOfHardCrashingTests.Where(tc => collectingReporter.ReportedTestResults.Any(tr => tc.Equals(tr.TestCase) && (tr.Outcome == TestOutcome.Passed || tr.Outcome == TestOutcome.Failed)))); }
// 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); } }
// ReSharper disable once UnusedParameter.Local private void RunTestsFromExecutable(string executable, IEnumerable <TestCase> allTestCases, IEnumerable <TestCase> testCasesToRun, string baseDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher) { string resultXmlFile = Path.GetTempFileName(); string workingDir = Path.GetDirectoryName(executable); 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); TestEnvironment.DebugInfo("Executing command '" + executable + " " + arguments.CommandLine + "'."); 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); FrameworkReporter.ReportTestResults(results); serializer.UpdateTestDurations(results); } }
// 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); } } } }
private ITestsSplitter GetTestsSplitter(TestCase[] testCasesToRun) { var serializer = new TestDurationSerializer(); IDictionary <TestCase, int> durations = serializer.ReadTestDurations(testCasesToRun); ITestsSplitter splitter; if (durations.Count < testCasesToRun.Length) { splitter = new NumberBasedTestsSplitter(testCasesToRun, TestEnvironment); TestEnvironment.DebugInfo("Using splitter based on number of tests"); } else { splitter = new DurationBasedTestsSplitter(durations, TestEnvironment); TestEnvironment.DebugInfo("Using splitter based on test durations"); } return(splitter); }
private ITestsSplitter GetTestsSplitter(TestCase[] testCasesToRun) { IDictionary <TestCase, int> durations = null; try { var serializer = new TestDurationSerializer(); durations = serializer.ReadTestDurations(testCasesToRun); foreach (KeyValuePair <TestCase, int> duration in durations) { if (!_schedulingAnalyzer.AddExpectedDuration(duration.Key, duration.Value)) { _logger.DebugWarning(String.Format(Resources.TestCaseInAnalyzer, duration.Key.FullyQualifiedName)); } } } catch (InvalidTestDurationsException e) { _logger.LogWarning(string.Format(Resources.ReadTestDurationError, e.Message)); } ITestsSplitter splitter; if (durations == null || durations.Count < testCasesToRun.Length) { splitter = new NumberBasedTestsSplitter(testCasesToRun, _settings); _logger.DebugInfo(Resources.UsingSplitterOnNumber); } else { splitter = new DurationBasedTestsSplitter(durations, _settings); _logger.DebugInfo(Resources.UsingSplitterOnDuration); } return(splitter); }