Beispiel #1
0
        // 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());
        }