public TimingLogger LogTime(string leadText = "") { if (settings.Verbosity < 5) { return(this); } var ts = Stopwatch.Elapsed; string elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; logger.Info($"{leadText} :Elapsed: {elapsedTime}"); return(this); }
public void GenerateTestOutput(NUnitResults testResults, string assemblyPath, string testOutputXmlFolder) { if (!settings.UseTestOutputXml) { return; } string path = GetXmlFilePath(testOutputXmlFolder, Path.GetFileNameWithoutExtension(assemblyPath), "xml"); var resultService = GetService <IResultService>(); // Following null argument should work for nunit3 format. Empty array is OK as well. // If you decide to handle other formats in the runsettings, it needs more work. var resultWriter = resultService.GetResultWriter("nunit3", null); resultWriter.WriteResultFile(testResults.FullTopNode, path); logger.Info($" Test results written to {path}"); }
public TestResultSet GetVSTestResults(XmlNode resultNode, ICollection <XmlNode> outputNodes) { var results = new List <VSTestResult>(); var testcaseResult = GetBasicResult(resultNode, outputNodes); if (testcaseResult != null) { if (testcaseResult.Outcome == TestOutcome.Failed || testcaseResult.Outcome == TestOutcome.NotFound) { testcaseResult.ErrorMessage = resultNode.SelectSingleNode("failure/message")?.InnerText; testcaseResult.ErrorStackTrace = resultNode.SelectSingleNode("failure/stack-trace")?.InnerText; // find stacktrace in assertion nodes if not defined (seems .netcore2.0 doesn't provide stack-trace for Assert.Fail("abc")) if (testcaseResult.ErrorStackTrace == null) { string stackTrace = string.Empty; foreach (XmlNode assertionStacktraceNode in resultNode.SelectNodes("assertions/assertion/stack-trace")) { stackTrace += assertionStacktraceNode.InnerText; } testcaseResult.ErrorStackTrace = stackTrace; } } else if (testcaseResult.Outcome == TestOutcome.Skipped || testcaseResult.Outcome == TestOutcome.None) { testcaseResult.ErrorMessage = resultNode.SelectSingleNode("reason/message")?.InnerText; } _logger.Info($"Test case { testcaseResult.DisplayName } is { testcaseResult.Outcome.ToString() }"); results.Add(testcaseResult); } if (results.Count == 0) { var result = MakeTestResultFromLegacyXmlNode(resultNode, outputNodes); if (result != null) { results.Add(result); } } return(new TestResultSet { TestCaseResult = testcaseResult, TestResults = results }); }
public IList <TestCase> Convert(NUnitResults discoveryResults, ITestLogger logger, string assemblyPath, IAdapterSettings settings) { var nunitTestCases = discoveryResults.TestCases(); TestConverter = new TestConverter(logger, assemblyPath, settings); var loadedTestCases = new List <TestCase>(); // As a side effect of calling TestConverter.ConvertTestCase, // the converter's cache of all test cases is populated as well. // All future calls to convert a test case may now use the cache. foreach (XmlNode testNode in nunitTestCases) { loadedTestCases.Add(TestConverter.ConvertTestCase(new NUnitTestCase(testNode))); } logger.Info($" NUnit3TestExecutor discovered {loadedTestCases.Count} of {nunitTestCases.Count} NUnit test cases"); return(loadedTestCases); }
public void Load(string settingsXml) { if (string.IsNullOrEmpty(settingsXml)) { settingsXml = "<RunSettings />"; } // Visual Studio already gives a good error message if the .runsettings // file is poorly formed, so we don't need to do anything more. var doc = new XmlDocument(); doc.LoadXml(settingsXml); var nunitNode = doc.SelectSingleNode("RunSettings/NUnit"); Verbosity = GetInnerTextAsInt(nunitNode, nameof(Verbosity), 0); _logger.Verbosity = Verbosity; var runConfiguration = doc.SelectSingleNode("RunSettings/RunConfiguration"); MaxCpuCount = GetInnerTextAsInt(runConfiguration, nameof(MaxCpuCount), -1); ResultsDirectory = GetInnerTextWithLog(runConfiguration, nameof(ResultsDirectory)); TargetPlatform = GetInnerTextWithLog(runConfiguration, nameof(TargetPlatform)); TargetFrameworkVersion = GetInnerTextWithLog(runConfiguration, nameof(TargetFrameworkVersion)); TestAdapterPaths = GetInnerTextWithLog(runConfiguration, nameof(TestAdapterPaths)); CollectSourceInformation = GetInnerTextAsBool(runConfiguration, nameof(CollectSourceInformation), true); DisableAppDomain = GetInnerTextAsBool(runConfiguration, nameof(DisableAppDomain), false); DisableParallelization = GetInnerTextAsBool(runConfiguration, nameof(DisableParallelization), false); DesignMode = GetInnerTextAsBool(runConfiguration, nameof(DesignMode), false); CollectDataForEachTestSeparately = GetInnerTextAsBool(runConfiguration, nameof(CollectDataForEachTestSeparately), false); TestProperties = new Dictionary <string, string>(); UpdateTestProperties(); // NUnit settings InternalTraceLevel = GetInnerTextWithLog(nunitNode, nameof(InternalTraceLevel), "Off", "Error", "Warning", "Info", "Verbose", "Debug"); WorkDirectory = GetInnerTextWithLog(nunitNode, nameof(WorkDirectory)); Where = GetInnerTextWithLog(nunitNode, nameof(Where)); DefaultTimeout = GetInnerTextAsInt(nunitNode, nameof(DefaultTimeout), 0); NumberOfTestWorkers = GetInnerTextAsInt(nunitNode, nameof(NumberOfTestWorkers), -1); ShadowCopyFiles = GetInnerTextAsBool(nunitNode, nameof(ShadowCopyFiles), false); UseVsKeepEngineRunning = GetInnerTextAsBool(nunitNode, nameof(UseVsKeepEngineRunning), false); BasePath = GetInnerTextWithLog(nunitNode, nameof(BasePath)); PrivateBinPath = GetInnerTextWithLog(nunitNode, nameof(PrivateBinPath)); TestOutputXml = GetInnerTextWithLog(nunitNode, nameof(TestOutputXml)); NewOutputXmlFileForEachRun = GetInnerTextAsBool(nunitNode, nameof(NewOutputXmlFileForEachRun), false); RandomSeed = GetInnerTextAsNullableInt(nunitNode, nameof(RandomSeed)); RandomSeedSpecified = RandomSeed.HasValue; if (!RandomSeedSpecified) { RandomSeed = new Random().Next(); } DefaultTestNamePattern = GetInnerTextWithLog(nunitNode, nameof(DefaultTestNamePattern)); ShowInternalProperties = GetInnerTextAsBool(nunitNode, nameof(ShowInternalProperties), false); UseParentFQNForParametrizedTests = GetInnerTextAsBool(nunitNode, nameof(UseParentFQNForParametrizedTests), false); UseNUnitIdforTestCaseId = GetInnerTextAsBool(nunitNode, nameof(UseNUnitIdforTestCaseId), false); ConsoleOut = GetInnerTextAsInt(nunitNode, nameof(ConsoleOut), 1); // 0 no output to console, 1 : output to console StopOnError = GetInnerTextAsBool(nunitNode, nameof(StopOnError), false); DiscoveryMethod = MapEnum(GetInnerText(nunitNode, nameof(DiscoveryMethod), Verbosity > 0), DiscoveryMethod.Current); UseNUnitFilter = GetInnerTextAsBool(nunitNode, nameof(UseNUnitFilter), true); // Engine settings SkipNonTestAssemblies = GetInnerTextAsBool(nunitNode, nameof(SkipNonTestAssemblies), true); AssemblySelectLimit = GetInnerTextAsInt(nunitNode, nameof(AssemblySelectLimit), 2000); // Adapter Diagnostics DumpXmlTestDiscovery = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestDiscovery), false); DumpXmlTestResults = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestResults), false); DumpVsInput = GetInnerTextAsBool(nunitNode, nameof(DumpVsInput), false); FreakMode = GetInnerTextAsBool(nunitNode, nameof(FreakMode), false); // End Diagnostics // Adapter Display Options MapDisplayName(GetInnerText(nunitNode, nameof(DisplayName), Verbosity > 0)); FullnameSeparator = GetInnerText(nunitNode, nameof(FullnameSeparator), Verbosity > 0)?[0] ?? ':'; // EndDisplay PreFilter = GetInnerTextAsBool(nunitNode, nameof(PreFilter), false); MapTestCategory(GetInnerText(nunitNode, nameof(VsTestCategoryType), Verbosity > 0)); MapWarningTo = MapWarningOutcome(GetInnerText(nunitNode, nameof(MapWarningTo), Verbosity > 0)); UseTestNameInConsoleOutput = GetInnerTextAsBool(nunitNode, nameof(UseTestNameInConsoleOutput), false); var inProcDataCollectorNode = doc.SelectSingleNode("RunSettings/InProcDataCollectionRunSettings/InProcDataCollectors"); InProcDataCollectorsAvailable = inProcDataCollectorNode != null && inProcDataCollectorNode.SelectNodes("InProcDataCollector")?.Count > 0; // Older versions of VS do not pass the CollectDataForEachTestSeparately configuration together with the LiveUnitTesting collector. // However, the adapter is expected to run in CollectDataForEachTestSeparately mode. // As a result for backwards compatibility reasons enable CollectDataForEachTestSeparately mode whenever LiveUnitTesting collector is being used. var hasLiveUnitTestingDataCollector = inProcDataCollectorNode?.SelectSingleNode( "InProcDataCollector[@uri='InProcDataCollector://Microsoft/LiveUnitTesting/1.0']") != null; // TestPlatform can opt-in to run tests one at a time so that the InProcDataCollectors can collect the data for each one of them separately. // In that case, we need to ensure that tests do not run in parallel and the test started/test ended events are sent synchronously. if (CollectDataForEachTestSeparately || hasLiveUnitTestingDataCollector) { NumberOfTestWorkers = 0; SynchronousEvents = true; if (Verbosity >= 4) { if (!InProcDataCollectorsAvailable) { _logger.Info( "CollectDataForEachTestSeparately is set, which is used to make InProcDataCollectors collect data for each test separately. No InProcDataCollectors can be found, thus the tests will run slower unnecessarily."); } } } // If DisableAppDomain settings is passed from the testplatform, set the DomainUsage to None. if (DisableAppDomain) { DomainUsage = "None"; } // Update NumberOfTestWorkers based on the DisableParallelization and NumberOfTestWorkers from runsettings. UpdateNumberOfTestWorkers(); void UpdateTestProperties() { foreach (XmlNode node in doc.SelectNodes("RunSettings/TestRunParameters/Parameter")) { var key = node.GetAttribute("name"); var value = node.GetAttribute("value"); if (key != null && value != null) { TestProperties.Add(key, value); } } } }