private static string BuildQuery(IEnumerable <ITestResult> resultList) { var results = resultList.ToArray(); Logger.Exec(Logger.LogLevel.Debug, results.Select(e => e.FullName)); const char pipe = '|'; var writeArg = new Func <ITestResult, string>(res => { var name = res.FullName; if (name.Contains("(")) { // Enclose the name in quote in order to run parameterized fixtures/tests. name = $"\\\"{name}\\\""; } return($"test=={name} {pipe} "); }); return(results.Aggregate(string.Empty, (query, fixture) => { return fixture.Children.Where(child => child.ResultState.Status == TestStatus.Failed) .Select(child => { // If dealing with a parameterized test, get its failed child results. return child.HasChildren ? child.Children.Where(c => c.ResultState.Status == TestStatus.Failed) .Aggregate(string.Empty, (line, c) => line + writeArg(c)) : writeArg(child); }) // Remove duplicates. (if test cases are used) .Distinct() .Aggregate(query, (tot, cur) => tot + cur); }).Trim(pipe, ' ')); }
/// <summary> /// Builds a TSL query for the currently failed tests and writes it to a file using the provided location. /// </summary> /// <param name="fileName">Absolute path to the file what the built query should be written to.</param> public static void WriteRetryQueryToFile(string fileName) { Logger.Exec(Logger.LogLevel.Debug, fileName); var query = BuildRetryQuery(); if (string.IsNullOrEmpty(query)) { return; } WriteTslToFile(query, fileName); }
/// <summary> /// Builds a TSL query for the currently failed tests. /// </summary> /// <returns>NUnit TSL based query.</returns> public static string BuildRetryQuery() { Logger.Exec(Logger.LogLevel.Debug); var runResult = TestExecutionContext.CurrentContext.CurrentResult; if (runResult.ResultState.Status == TestStatus.Passed) { return(string.Empty); } var failedFixturesResults = GetFailedResults(runResult); return(BuildQuery(failedFixturesResults)); }
private static void WriteTslToFile(string query, string fileName) { Logger.Exec(Logger.LogLevel.Debug, query, fileName); File.WriteAllText(fileName, query); }