Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            List <string> xmlConfigFileNameArray = new List <string>();

            string pathOfTestSuites = Path.Combine(AppContext.BaseDirectory, "TestSuites");

            if (!Directory.Exists(pathOfTestSuites))
            {
                Directory.CreateDirectory(pathOfTestSuites);
            }

            if (args.Length > 1)
            {
                xmlConfigFileNameArray = args.Skip(1).ToList();
            }
            else
            {
                xmlConfigFileNameArray = Directory.GetFiles(pathOfTestSuites, "*.xml", SearchOption.TopDirectoryOnly).ToList();
            }

            foreach (var moduleXmlFilePath in xmlConfigFileNameArray)
            {
                //moduleXmlFilePath = "D:\\TFS_REPO\\Hackathon2018_ATOM\\AurigoTest\\ModuleXYZ_TestSuite\\ModuleXYZ_TestSuite.xml";

                List <string> methodsToRun = null;

                TestSuiteConfigFile tsConfigFile = ParseConfigXmlAndExtractTestcasesToRun(moduleXmlFilePath, out methodsToRun);

                var dllPath = Path.Combine(pathOfTestSuites, tsConfigFile.LibraryAssemblyName);

                if (!dllPath.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
                {
                    dllPath += ".dll";
                }

                if (!File.Exists(dllPath))
                {
                    Console.WriteLine($"Missing dll {tsConfigFile.LibraryAssemblyName}");
                    continue;
                }

                try
                {
                    //Load the assembly from the specified path.
                    var MyAssembly = Assembly.LoadFrom(dllPath);

                    var obj = MyAssembly.CreateInstance(tsConfigFile.LibraryName);

                    ITestSuiteBase tsbase = obj as ITestSuiteBase;

                    tsbase.RunTest(methodsToRun);
                }
                catch (Exception e)
                {
                }
            }
        }
Exemplo n.º 2
0
        private TestSuiteConfigFile Get_TestSuiteConfigFile_Object(List <string> scenarioMethodNames, TestCaseScenario scenarioConfig)
        {
            TestSuiteConfigFile config = new TestSuiteConfigFile();

            config.LibraryName         = scenarioConfig.ModuleConfig.AutoGeneratedProjectNamespace + "." + "MasterRunner_AutoGenTests";
            config.LibraryAssemblyName = scenarioConfig.ModuleConfig.AssemblyName;

            RunConfigObject runObject = new RunConfigObject();

            runObject.Run     = "1-" + scenarioMethodNames.Count;
            runObject.RunUser = true;
            config.RunConfig  = runObject;

            List <TestDefinition> tests = new List <TestDefinition>();

            config.TestDescriptions = new List <TestDescription>();

            int scenarioId = 1;

            scenarioMethodNames.ForEach((scenario) =>
            {
                TestDefinition test = new TestDefinition();
                test.Method         = scenario;
                test.Id             = scenarioId++;
                tests.Add(test);

                var description = new TestDescription
                {
                    Id          = test.Id,
                    Description = string.Join(Environment.NewLine, scenarioConfig.Scenarios.Find(s => s.Name == scenario).ScenarioDescription)
                };

                config.TestDescriptions.Add(description);
            });

            config.TestDefinitionList = tests;

            return(config);
        }
Exemplo n.º 3
0
 public TestSuiteXmlFileGenerator(string moduleId, string dateTimeStampAppend, TestSuiteConfigFile testSuiteConfigFileObject)
 {
     this._ModuleId                 = moduleId;
     this._DateTimeStamp            = dateTimeStampAppend;
     this.TestSuiteConfigFileObject = testSuiteConfigFileObject;
 }
Exemplo n.º 4
0
        private static TestSuiteConfigFile ParseConfigXmlAndExtractTestcasesToRun(string filenameWithFullPath, out List <string> methodsToRun)
        {
            methodsToRun = new List <string>();

            TestSuiteConfigFile tsConfigFile = null;

            try
            {
                var xs = new XmlSerializer(typeof(TestSuiteConfigFile));

                var fReader = new System.IO.FileStream(filenameWithFullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                tsConfigFile = xs.Deserialize(fReader) as TestSuiteConfigFile;
            }
            catch (Exception e)
            {
                throw e;
            }

            List <int> run_IdList    = (!string.IsNullOrWhiteSpace(tsConfigFile.RunConfig.Run)) ? ParseNumberRangeFormat(tsConfigFile.RunConfig.Run) : new List <int>();
            List <int> no_run_IdList = (!string.IsNullOrWhiteSpace(tsConfigFile.RunConfig.NoRun)) ? ParseNumberRangeFormat(tsConfigFile.RunConfig.NoRun) : new List <int>();

            List <int> final_run_IdList   = new List <int>();
            List <int> final_noRun_IdList = new List <int>();

            if (run_IdList.Any())
            {
                if (no_run_IdList.Any())
                {
                    final_run_IdList = run_IdList.Where(t => !no_run_IdList.Contains(t)).ToList();
                }
                else
                {
                    final_run_IdList = run_IdList;
                }
            }
            else
            {
                if (no_run_IdList.Any())
                {
                    final_noRun_IdList = no_run_IdList;
                }
            }

            //Now extract method names
            if (final_run_IdList.Any())
            {
                foreach (var id in final_run_IdList)
                {
                    var testItem = tsConfigFile.TestDefinitionList.FirstOrDefault(t => t.Id == id);
                    if (testItem != null)
                    {
                        methodsToRun.Add(testItem.Method);
                    }
                }
            }
            else
            {
                if (final_noRun_IdList.Any())
                {
                    methodsToRun = tsConfigFile.TestDefinitionList.Where(t => !final_noRun_IdList.Contains(t.Id)).Select(t => t.Method).ToList();
                }
                else
                {
                    methodsToRun = tsConfigFile.TestDefinitionList.Select(t => t.Method).ToList();
                }
            }

            return(tsConfigFile);
        }