public static KarmaSettings Read(string path, IKarmaLogger logger) { logger.Info("Reading settings from {0}", path); KarmaSettings settings = null; if (PathUtils.PathHasFileName(path, Globals.SettingsFilename) && File.Exists(path)) { try { settings = JsonConvert.DeserializeObject <KarmaSettings>(File.ReadAllText(path, Encoding.UTF8)); settings.SettingsFile = path; } catch (Exception ex) { logger.Error(ex.Message); } } else { settings = new KarmaSettings { KarmaConfigFile = Path.GetFileName(path) }; } settings.Directory = Path.GetDirectoryName(path); return(settings); }
public IEnumerable <TestCase> GetTests(IEnumerable <string> sources, IKarmaLogger logger) { try { return(sources.SelectMany(s => GetTests(s, logger)).ToList()); } catch (Exception ex) { logger.Error(ex.Message); return(Enumerable.Empty <TestCase>()); } }
private void RunTests(string source, IEnumerable <TestCase> tests, KarmaTestResults.Karma karma, IFrameworkHandle frameworkHandle, IKarmaLogger logger) { var vsConfig = CreateVsConfig(tests, karma); var runKarma = Run(source, vsConfig, logger); if (runKarma == null) { logger.Error("No karma"); return; } var consolidatedResults = runKarma.ConsolidateResults(logger); var testNames = tests.Select(t => t.DisplayName).Union(consolidatedResults.Select(r => r.Test.DisplayName)); var results = from displayName in testNames join test in tests on displayName equals test.DisplayName into test_ from test in test_.DefaultIfEmpty() join result in consolidatedResults on displayName equals result.Test.DisplayName into result_ from result in result_.DefaultIfEmpty() select new TestCaseResult(test, result, source); foreach (var result in results) { frameworkHandle.RecordStart(result.Test); foreach (var res in result.Result.Results) { frameworkHandle.RecordResult(new TestResult(result.Test) { ComputerName = Environment.MachineName, DisplayName = res.Browser.Name, Outcome = res.Outcome, Duration = res.Time, ErrorMessage = res.Message }); } frameworkHandle.RecordEnd(result.Test, result.Result.Outcome); } }