public virtual void CleanUp() { if (State.PageInvalidated || Is.AjaxActive()) { Refresh(); } var alert = State.GetActiveAlert(); if (alert != null) { alert.Dismiss(); State.ActualizeAlerts(); if (State.GetActiveAlert() != null) { Refresh(); } } try { foreach (var overlay in State.GetOverlays()) { overlay.Close(); } } catch (Exception e) { Log.Error("Error occured while closing overlay."); Log.Error(e.Message); Refresh(); } }
public Settings(string name, string configFile, Func<string, bool> fileExists, string baseDirectory, ITestLogger logger) { Name = name; Logger = logger; try { Directory = Path.GetDirectoryName(configFile); SettingsFile = configFile; Json.PopulateFromFile(SettingsFile, this); Name = Name ?? name; BatchInterval = BatchInterval ?? 250; if (AreValid) { LogDirectory = GetFullPath(LogDirectory ?? ""); if (LogToFile) { logger.AddLogger(LogFilePath); } } else { LogDirectory = ""; LogToFile = false; } } catch (Exception ex) { _validator.Validate(false, "Could not read settings: {0}", ex.Message); logger.Error(ex, "Could not read settings"); } }
public KarmaSettings(string name, string configFile, Func <string, bool> fileExists, string baseDirectory, ITestLogger logger) { HasSettingsFile = false; Name = name; Logger = logger; try { Directory = Path.GetDirectoryName(configFile); SettingsFile = GetFullPath(Globals.SettingsFilename); KarmaConfigFile = GetFullPath(Globals.KarmaConfigFilename); if (PathUtils.PathHasFileName(configFile, Globals.SettingsFilename)) { Json.PopulateFromFile(configFile, this); KarmaConfigFile = string.IsNullOrWhiteSpace(KarmaConfigFile) ? GetFullPath(Globals.KarmaConfigFilename) : GetFullPath(KarmaConfigFile); _validator.Validate(fileExists(SettingsFile), "Settings file not found: {0}", PathUtils.GetRelativePath(baseDirectory, SettingsFile)); _validator.Validate(fileExists(KarmaConfigFile), "Karma configuration file not found: {0}", PathUtils.GetRelativePath(baseDirectory, KarmaConfigFile)); HasSettingsFile = true; } else { KarmaConfigFile = GetFullPath(configFile); _validator.Validate(fileExists(KarmaConfigFile), "Karma configuration file not found: {0}", PathUtils.GetRelativePath(baseDirectory, KarmaConfigFile)); } Name = Name ?? name; if (AreValid) { LogDirectory = GetFullPath(LogDirectory ?? ""); if (LogToFile) { logger.AddLogger(LogFilePath); } } else { LogDirectory = ""; LogToFile = false; } } catch (Exception ex) { _validator.Validate(false, "Could not read settings: {0}", ex.Message); logger.Error(ex, "Could not read settings"); } }
public KarmaSettings(string name, string configFile, Func<string, bool> fileExists, string baseDirectory, ITestLogger logger) { HasSettingsFile = false; Name = name; Logger = logger; try { Directory = Path.GetDirectoryName(configFile); SettingsFile = GetFullPath(Globals.SettingsFilename); KarmaConfigFile = GetFullPath(Globals.KarmaConfigFilename); if (PathUtils.PathHasFileName(configFile, Globals.SettingsFilename)) { Json.PopulateFromFile(configFile, this); KarmaConfigFile = string.IsNullOrWhiteSpace(KarmaConfigFile) ? GetFullPath(Globals.KarmaConfigFilename) : GetFullPath(KarmaConfigFile); _validator.Validate(fileExists(SettingsFile), "Settings file not found: {0}", PathUtils.GetRelativePath(baseDirectory, SettingsFile)); _validator.Validate(fileExists(KarmaConfigFile), "Karma configuration file not found: {0}", PathUtils.GetRelativePath(baseDirectory, KarmaConfigFile)); HasSettingsFile = true; } else { KarmaConfigFile = GetFullPath(configFile); _validator.Validate(fileExists(KarmaConfigFile), "Karma configuration file not found: {0}", PathUtils.GetRelativePath(baseDirectory, KarmaConfigFile)); } Name = Name ?? name; if (AreValid) { LogDirectory = GetFullPath(LogDirectory ?? ""); if (LogToFile) { logger.AddLogger(LogFilePath); } } else { LogDirectory = ""; LogToFile = false; } } catch (Exception ex) { _validator.Validate(false, "Could not read settings: {0}", ex.Message); logger.Error(ex, "Could not read settings"); } }
protected TestContainerDiscoverer( IServiceProvider serviceProvider, ITestsService testsService, TestSettingsProvider testSettingsProvider, ITestLogger logger ) { Logger = logger; try { TestSettingsProvider = testSettingsProvider; TestAdapterInfo = CreateTestAdapterInfo(); Containers = new TestContainerList(this); ServiceProvider = serviceProvider; _testsService = testsService; SolutionListener = new SolutionListener(serviceProvider); SolutionListener.SolutionLoaded += OnSolutionLoaded; SolutionListener.SolutionUnloaded += OnSolutionUnloaded; SolutionListener.ProjectChanged += OnSolutionProjectChanged; SolutionListener.StartListening(); ProjectListener = new ProjectListener(serviceProvider, Logger); ProjectListener.FileAdded += (source, e) => OnProjectFileAdded(e.Project, e.File); ProjectListener.FileRemoved += (source, e) => OnProjectFileRemoved(e.Project, e.File); ProjectListener.FileRenamed += (source, e) => OnProjectFileRenamed(e.Project, e.OldFile, e.NewFile); ProjectListener.StartListening(); RunScheduler = new Scheduler(250, RunTestsInternal); RefreshTestContainersScheduler = new Scheduler<string>(250, RefreshTestContainersInternal); Logger.Debug("TestContainerDiscoverer created"); } catch (Exception ex) { Logger.Error(ex); throw; } }
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(); string ValidatedPath(string path, string purpose) { try { if (string.IsNullOrEmpty(WorkDirectory)) { return(Path.GetFullPath(path)); } if (Path.IsPathRooted(path)) { return(Path.GetFullPath(path)); } return(Path.GetFullPath(Path.Combine(WorkDirectory, path))); } catch (Exception) { _logger.Error($" Invalid path for {purpose}: {path}"); throw; } } 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); } } } }