static void Main(string[] args)
        {
            var processor     = new UnityTestRunnerResultsProcessor();
            var optionsParser = new OptionsParser();

            Console.WriteLine("Reading parameters and validating test results....");
            optionsParser.ParseOptions(processor, args);

            var logParser = new UnityLogParser();
            var xmlParser = new TestResultXmlParser();

            Console.WriteLine("Trying to parse Unity version and test metadata...");
            logParser.TryParseProductVersion(processor);
            logParser.TryParseTestArguments(processor);
            Console.WriteLine("Trying to parse test results...");
            xmlParser.ParseTestResults(processor);

            Console.WriteLine("Generating test result JSON file...");
            processor.GenerateTestResultJson();
            processor.GenerateConsoleOutput();
            Console.WriteLine("Generating HTML test report...");
            processor.GenerateHtmlReport();

            if (processor.GetOverallTestResults())
            {
                Environment.Exit(0);
            }
            else
            {
                Environment.Exit(1);
            }
        }
Example #2
0
        public void ParseOptions(UnityTestRunnerResultsProcessor processor, IEnumerable <string> args)
        {
            var os = GetOptions(processor);

            try
            {
                var remaining = os.Parse(args);

                if (help)
                {
                    ShowHelp(string.Empty, os);
                }

                if (string.IsNullOrEmpty(processor.TestResultsPath) || string.IsNullOrEmpty(processor.ReportPath))
                {
                    ShowHelp("Missing required option --resultsPath=(directoryPath)", os);
                }

                if (remaining.Any())
                {
                    var errorMessage = string.Format("Unknown option: '{0}.\r\n'", remaining[0]);
                    ShowHelp(errorMessage, os);
                }
            }
            catch (Exception e)
            {
                ShowHelp(string.Format("Error encountered while parsing option: {0}.\r\n", e.Message), os);
            }
        }
        /// <summary>
        /// Parse production version information from unity log
        /// </summary>
        /// <param name="processor">The processer</param>
        public void TryParseProductVersion(UnityTestRunnerResultsProcessor processor)
        {
            var version = new ProductVersion();

            try
            {
                using (StreamReader sr = new StreamReader(processor.LogFilePath))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();
                        if (line.StartsWith(unityInfoLinePrefix, StringComparison.CurrentCultureIgnoreCase))
                        {
                            var parts = line.Split('\'');
                            version.branch = parts[1];
                            var unityInfo = parts[3].Split(' ');
                            version.unity_version  = unityInfo[0];
                            version.revision       = unityInfo[1];
                            version.revisionNumber = Convert.ToInt64(unityInfo[3]);
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                processor.AddProducVersionToTestResult(version);
            }
        }
        public void ParseTestResults(UnityTestRunnerResultsProcessor processor)
        {
            this.testProject = processor.TestProjectName;
            var testResultXML = TryLoadResultXmlFile(processor.XMLFilePath);

            this.resultsPath = processor.ReportPath;

            var testSummary = TryParseTestSummary(testResultXML);

            processor.AddTestSummaryToTestResult(testSummary);

            var testCaseResult = TryParseTestCaseResults(testResultXML);

            processor.AddTestCaseResultsToTestResult(testCaseResult);

            var testRunSummary = TryParseTestRunSummary(testResultXML, testSummary);

            processor.AddTestRunSummaryToTestResult(testRunSummary);
        }
Example #5
0
 private OptionSet GetOptions(UnityTestRunnerResultsProcessor processor)
 {
     return(new OptionSet()
            .Add("?|help|h", "Prints out the options.", option => help = option != null)
            .Add("resultsPath=", "REQUIRED - Path to a directory where test result XML file and Unity log file can be find. ",
                 resultsPath =>
     {
         processor.AddTestResultsPath(resultsPath, "resultsPath");
     })
            .Add("resultXMLName|XMLName:", "OPTIONAL - Name of test result XML file name.",
                 xmlName =>
     {
         processor.AddFileName(xmlName, "resultXMLName");
     })
            .Add("unityLogName|LogName:", "OPTIONAL - Name of Unity log file name.",
                 logName =>
     {
         processor.AddFileName(logName, "unityLogName");
     })
            .Add("report|reportdirpath:", "OPTIONAL - Path to where the report will be written. Default is the given test results path.",
                 processor.AddReportDirPath));
 }
        /// <summary>
        /// Parse test arguments from unity log
        /// </summary>
        /// <param name="processor"></param>
        public void TryParseTestArguments(UnityTestRunnerResultsProcessor processor)
        {
            var arguments       = new TestArguments();
            var listOfArguments = new List <string>();

            try
            {
                using (StreamReader sr = new StreamReader(processor.LogFilePath))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();
                        if (line.Contains(testArgumentsHeader))
                        {
                            string arg = sr.ReadLine();
                            arg = sr.ReadLine();    // The first line below header is Unity.exe, skip this
                            while (!arg.StartsWith(testArgumentsTailPrefix, StringComparison.CurrentCultureIgnoreCase))
                            {
                                listOfArguments.Add(arg);
                                arg = sr.ReadLine();
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                arguments.args = listOfArguments;
                processor.AddTestArgumentsToTestResult(arguments);
            }
        }