Example #1
0
        public static int Execute(CommandlineOptions options)
        {
            var serviceProvider = Bootstrapper.CreateContainer(new FileBasedDataStore(options.Dir), new ServiceCollection(), options.LogLevel);

            var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>();

            var logger = loggerFactory.CreateLogger <Program>();

            logger.LogInformation("TestCases [{0}]", options.Dir);

            var parsedOptions = options.Options?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(_ => _.LeftOf("="), _ => _.RightOf("=")) ?? new Dictionary <string, string>();

            parsedOptions.Add("ct.dir", options.Dir);
            parsedOptions.Add("ct.rebase", options.Rebase ? bool.TrueString : bool.FalseString);
            parsedOptions.Add("ct.deferExceptions", options.SuppressExceptions ? bool.TrueString : bool.FalseString);

            var results = serviceProvider.GetRequiredService <Testing.CyberTester>().RunTests(serviceProvider.GetServices <ITestSession>(), parsedOptions).ToList();

            var failedTestsCount         = results.Count(_ => _.Exception != null);
            var nonMutedfailedTestsCount = results.Count(_ => _.Exception != null && !_.IsMuted);

            logger.LogInformation("Tests execution finished. Testcases: {0}, total failures: {1}, non-muted failures: {2}", results.Count, failedTestsCount, nonMutedfailedTestsCount);

            XElement root = new XElement("TestResults", results.Select(_ => new XElement("Test", new XAttribute("id", _.TestCase.Id), new XAttribute("status", _.Exception == null ? "succeeded" : "failed"), new XAttribute("muted", _.IsMuted), _.Description == null ? null : _.Description.Root)));

            root.Save("TestSessionResults.xml");

            return(nonMutedfailedTestsCount);
        }
Example #2
0
        public static int Main(string[] args)
        {
            int result       = -1;
            var parserResult = Parser.Default.ParseArguments <CommandlineOptions>(args);

            if (parserResult.Tag == ParserResultType.Parsed)
            {
                CommandlineOptions parsedOptions = null;
                parserResult.WithParsed(options => parsedOptions = options);
                if (string.IsNullOrEmpty(parsedOptions.Dir))
                {
                    parsedOptions.Dir = Directory.GetCurrentDirectory();
                }

                result = Execute(parsedOptions);
            }
            return(result);
        }