Пример #1
0
        public void GenerateReport_CreateIndexFile()
        {
            var resultFolder = @"Reporting\Test1";

            ReportingHelper.GenerateHtmlReport(new ExecutionEnvironment()
            {
                OutputDirectoryLocation = "Reporting\\Test1"
            });
            Assert.IsTrue(File.Exists(Path.Combine(resultFolder, "index.html")));
        }
Пример #2
0
        public static async Task Main(string[] args)
        {
            var config = new NLog.Config.LoggingConfiguration();

            // Targets where to log to: File and Console
            //var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "file.txt" };
            //config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            // Rules for mapping loggers to targets
            var logconsole = new NLog.Targets.ConsoleTarget("logconsole");

            config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);

            // Apply config
            LogManager.Configuration = config;


            var fluentParser = SetupArguments();
            ICommandLineParserResult result;

            result = fluentParser.Parse(args);



            if (result.HasErrors == false)
            {
                List <string> tests = new List <string>();

                for (int index = 0; index < LogManager.Configuration.LoggingRules.Count; index++)
                {
                    LogManager.Configuration.LoggingRules[index].SetLoggingLevels(fluentParser.Object.LogLevel, LogLevel.Fatal);
                }

                if (fluentParser.Object.Tests != null)
                {
                    tests.AddRange(fluentParser.Object.Tests);
                }

                if (fluentParser.Object.TestsLocation != null)
                {
                    var testfiles = Directory.GetFiles(fluentParser.Object.TestsLocation, "*.json", SearchOption.TopDirectoryOnly);
                    foreach (var testfile in testfiles)
                    {
                        tests.Add(Path.Combine(fluentParser.Object.TestsLocation, testfile));
                    }
                }

                if (tests.Count > 0)
                {
                    if (fluentParser.Object.ParallelScope == ParallelScope.None)
                    {
                        _log_.Info("Executing tests in series");
                        List <ITest> testExecutions = new List <ITest>();
                        foreach (var test in tests)
                        {
                            testExecutions.Add(await ExecuteTestAsync(test, fluentParser.Object));
                        }
                        WriteTestResults(testExecutions);
                        ReportingHelper.GenerateHtmlReport(fluentParser.Object);
                    }

                    if (fluentParser.Object.ParallelScope == ParallelScope.All)
                    {
                        _log_.Info("Executing tests in parallel");
                        List <Task <ITest> > tasks = new List <Task <ITest> >();
                        foreach (var test in tests)
                        {
                            tasks.Add(ExecuteTestAsync(test, fluentParser.Object));
                        }

                        Task.WaitAll(tasks.ToArray());

                        var testExecutions = tasks.Select(ts => ts.Result);

                        WriteTestResults(testExecutions);
                        ReportingHelper.GenerateHtmlReport(fluentParser.Object);
                        if (testExecutions.Where(t => t.Failed.HasValue && t.Failed.Value).Count() > 0)
                        {
                            _log_.Error($"{testExecutions.Where(t => t.Failed.HasValue && t.Failed.Value).Count()} / {testExecutions.Count()} failed tests");
                            Environment.Exit(exitCode: 19);
                        }
                        else
                        {
                            Environment.Exit(exitCode: 0);
                        }
                    }
                }
                else
                {
                    _log_.Error("Spider-cli: ");
                    _log_.Error(result.ErrorText);
                    _log_.Error("Try `Spider-cli.exe --help' for more information.");
                    Environment.Exit(exitCode: 21);
                }
            }
        }