private static List <TestInfo> GetTestList(IEnumerable <string> dlls) { var testList = new List <TestInfo>(); // Find tests in the test dlls. foreach (var testDll in dlls) { testList.AddRange(RunTests.GetTestInfos(testDll)); } // Sort tests alphabetically. testList.Sort((x, y) => String.CompareOrdinal(x.TestMethod.Name, y.TestMethod.Name)); return(testList); }
// Load a list of tests specified on the command line as a comma-separated list. Any name prefixed with '@' // is a file containing test names separated by white space or new lines, with '#' indicating a comment. private static List <string> LoadList(string testList) { var inputList = testList.Split(','); var outputList = new List <string>(); // Check for empty list. if (inputList.Length == 1 && inputList[0] == "") { return(outputList); } foreach (var name in inputList) { if (name.StartsWith("@")) { var file = name.Substring(1); var lines = File.ReadAllLines(file); foreach (var line in lines) { // remove comments var lineParts = line.Split('#'); if (lineParts.Length > 0 && lineParts[0] != "") { // split multiple test names in one line outputList.AddRange(lineParts[0].Trim().Split(' ', '\t')); } } } else if (name.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase)) { foreach (var testInfo in RunTests.GetTestInfos(name)) { outputList.Add(testInfo.TestClassType.Name + "." + testInfo.TestMethod.Name); } } else { outputList.Add(name); } } return(outputList); }
// Load list of tests to be run into TestList. private static List <TestInfo> LoadTestList(CommandLineArgs commandLineArgs) { List <string> testNames; var testList = new List <TestInfo>(); // Clear forms/tests cache if desired. var formArg = commandLineArgs.ArgAsString("form"); // Load lists of tests to run. if (string.IsNullOrEmpty(formArg)) { testNames = LoadList(commandLineArgs.ArgAsString("test")); } // Find which tests best cover the desired forms. else { var formLookup = new FormLookup(); List <string> uncoveredForms; testNames = formLookup.FindTests(LoadList(formArg), out uncoveredForms); if (uncoveredForms.Count > 0) { MessageBox.Show("No tests found to show these Forms: " + string.Join(", ", uncoveredForms), "Warning"); return(testList); } } // Maintain order in list of explicitly specified tests var testDict = new Dictionary <string, int>(); for (int i = 0; i < testNames.Count; i++) { if (testDict.ContainsKey(testNames[i])) { MessageBox.Show("Duplicate test name: " + testNames[i]); throw new ArgumentException("Duplicate test name: " + testNames[i]); } testDict.Add(testNames[i], i); } var testArray = new TestInfo[testNames.Count]; var skipList = LoadList(commandLineArgs.ArgAsString("skip")); // Find tests in the test dlls. foreach (var testDll in TEST_DLLS) { foreach (var testInfo in RunTests.GetTestInfos(testDll)) { var testName = testInfo.TestClassType.Name + "." + testInfo.TestMethod.Name; if (testNames.Count == 0 || testNames.Contains(testName) || testNames.Contains(testInfo.TestMethod.Name)) { if (!skipList.Contains(testName) && !skipList.Contains(testInfo.TestMethod.Name)) { if (testNames.Count == 0) { testList.Add(testInfo); } else { string lookup = testNames.Contains(testName) ? testName : testInfo.TestMethod.Name; testArray[testDict[lookup]] = testInfo; } } } } } if (testNames.Count > 0) { testList.AddRange(testArray.Where(testInfo => testInfo != null)); } // Sort tests alphabetically, but run perf tests last for best coverage in a fixed amount of time. return(testList.OrderBy(e => e.IsPerfTest).ThenBy(e => e.TestMethod.Name).ToList()); }