Пример #1
0
        static int RunTests(string [] original_args)
        {
            Console.WriteLine("Running tests");
            var options = ApplicationOptions.Current;

            // we generate the logs in two different ways depending if the generate xml flag was
            // provided. If it was, we will write the xml file to the tcp writer if present, else
            // we will write the normal console output using the LogWriter
            var logger = new LogWriter(Console.Out);

            logger.MinimumLogLevel = MinimumLogLevel.Info;
            var testAssemblies = GetTestAssemblies();
            var runner         = RegisterType.IsXUnit ? (TestRunner) new XUnitTestRunner(logger) : new NUnitTestRunner(logger);
            var categories     = RegisterType.IsXUnit ?
                                 new List <string> {
                "failing",
                "nonmonotests",
                "outerloop",
                "nonosxtests"
            } :
            new List <string> {
                "MacNotWorking",
                "MobileNotWorking",
                "NotOnMac",
                "NotWorking",
                "ValueAdd",
                "CAS",
                "InetAccess",
                "NotWorkingLinqInterpreter"
            };

            if (RegisterType.IsXUnit)
            {
                // special case when we are using the xunit runner,
                // there is a trait we are not interested in which is
                // the Benchmark one
                var xunitRunner = runner as XUnitTestRunner;
                xunitRunner.AddFilter(XUnitFilter.CreateTraitFilter("Benchmark", "true", true));
            }

            runner.SkipCategories(categories);
            runner.Run(testAssemblies.ToList());

            if (options.ResultFile != null)
            {
                using (var writer = new StreamWriter(options.ResultFile)) {
                    runner.WriteResultsToFile(writer);
                }
                logger.Info($"Xml result can be found {options.ResultFile}");
            }

            logger.Info($"Tests run: {runner.TotalTests} Passed: {runner.PassedTests} Inconclusive: {runner.InconclusiveTests} Failed: {runner.FailedTests} Ignored: {runner.FilteredTests}");
            return(runner.FailedTests != 0 ? 1 : 0);
        }
Пример #2
0
        void RunTests()
        {
            var        options = ApplicationOptions.Current;
            TextWriter writer  = null;

            if (!string.IsNullOrEmpty(options.HostName) && string.IsNullOrEmpty(options.LogFile))
            {
                writer = new HttpTextWriter()
                {
                    HostName = options.HostName, Port = options.HostPort
                }
            }
            ;
            if (!string.IsNullOrEmpty(options.LogFile))
            {
                writer = new StreamWriter(options.LogFile);
            }

            // we generate the logs in two different ways depending if the generate xml flag was
            // provided. If it was, we will write the xml file to the tcp writer if present, else
            // we will write the normal console output using the LogWriter
            var logger = (writer == null || options.EnableXml) ? new LogWriter() : new LogWriter(writer);

            logger.MinimumLogLevel = MinimumLogLevel.Info;
            var testAssemblies = GetTestAssemblies();

            runner = RegisterType.IsXUnit ? (Xamarin.iOS.UnitTests.TestRunner) new XUnitTestRunner(logger) : new NUnitTestRunner(logger);
            var categories = RegisterType.IsXUnit ?
                             new List <string> {
                "failing",
                "nonmonotests",
                "outerloop",
                "nonosxtests"
            } :
            new List <string> {
                "MobileNotWorking",
                "NotOnMac",
                "NotWorking",
                "ValueAdd",
                "CAS",
                "InetAccess",
                "NotWorkingLinqInterpreter",
                "BitcodeNotSupported",
            };

            if (RegisterType.IsXUnit)
            {
                // special case when we are using the xunit runner,
                // there is a trait we are not interested in which is
                // the Benchmark one
                var xunitRunner = runner as XUnitTestRunner;
                xunitRunner.AddFilter(XUnitFilter.CreateTraitFilter("Benchmark", "true", true));
            }
            // add category filters if they have been added
            runner.SkipCategories(categories);

            // if we have ignore files, ignore those tests
            var skippedTests = IgnoreFileParser.ParseContentFiles(NSBundle.MainBundle.BundlePath);

            if (skippedTests.Any())
            {
                // ensure that we skip those tests that have been passed via the ignore files
                runner.SkipTests(skippedTests);
            }

            ThreadPool.QueueUserWorkItem((v) =>
            {
                BeginInvokeOnMainThread(() =>
                {
                    lblStatus.SetText(string.Format("{0} tests", runner.TotalTests));
                    runner.Run((IList <TestAssemblyInfo>)testAssemblies);
                    RenderResults();
                    cmdRun.SetEnabled(true);
                    cmdRun.SetHidden(false);
                    if (options.EnableXml)
                    {
                        runner.WriteResultsToFile(writer);
                        logger.Info("Xml file was written to the http listener.");
                    }
                    else
                    {
                        string resultsFilePath = runner.WriteResultsToFile();
                        logger.Info($"Xml result can be found {resultsFilePath}");
                    }
                    logger.Info($"Tests run: {runner.TotalTests} Passed: {runner.PassedTests} Inconclusive: {runner.InconclusiveTests} Failed: {runner.FailedTests} Ignored: {runner.FilteredTests}");
                    if (options.TerminateAfterExecution)
                    {
                        TerminateWithSuccess();
                    }
                });
            });
        }

        void RenderResults()
        {
            var options = ApplicationOptions.Current;

            if (runner.TotalTests == 0)
            {
                return;
            }

            lblSuccess.SetText(string.Format("P: {0}/{1} {2}%", runner.PassedTests, runner.TotalTests, 100 * runner.PassedTests / runner.TotalTests));
            lblFailed.SetText(string.Format("F: {0}/{1} {2}%", runner.FailedTests, runner.TotalTests, 100 * runner.FailedTests / runner.TotalTests));
            lblIgnInc.SetText(string.Format("I: {0}/{1} {2}%", (runner.SkippedTests + runner.InconclusiveTests), runner.TotalTests, 100 * (runner.SkippedTests + runner.InconclusiveTests) / runner.TotalTests));

            if (running == false && runner.PassedTests > 0)
            {
                if (runner.FailedTests == 0)
                {
                    lblSuccess.SetTextColor(UIKit.UIColor.Green);
                    lblStatus.SetTextColor(UIKit.UIColor.Green);
                    lblStatus.SetText("Success");
                }
                if (runner.FailedTests > 0)
                {
                    lblFailed.SetTextColor(UIKit.UIColor.Red);
                    lblStatus.SetTextColor(UIKit.UIColor.Red);
                    lblStatus.SetText("Failed");
                }
            }
        }

        partial void RunTests(NSObject obj)
        {
            RunTests();
        }
    }
Пример #3
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var           options = ApplicationOptions.Current;
            TcpTextWriter writer  = null;

            if (!string.IsNullOrEmpty(options.HostName))
            {
                writer = new TcpTextWriter(options.HostName, options.HostPort);
            }

            // we generate the logs in two different ways depending if the generate xml flag was
            // provided. If it was, we will write the xml file to the tcp writer if present, else
            // we will write the normal console output using the LogWriter
            var logger = (writer == null || options.EnableXml) ? new LogWriter() : new LogWriter(writer);

            logger.MinimumLogLevel = MinimumLogLevel.Info;
            var testAssemblies = GetTestAssemblies();
            var runner         = RegisterType.IsXUnit ? (Xamarin.iOS.UnitTests.TestRunner) new XUnitTestRunner(logger) : new NUnitTestRunner(logger);
            var categories     = RegisterType.IsXUnit ?
                                 new List <string> {
                "failing",
                "nonmonotests",
                "outerloop",
                "nonosxtests"
            } :
            new List <string> {
                "MobileNotWorking",
                "NotOnMac",
                "NotWorking",
                "ValueAdd",
                "CAS",
                "InetAccess",
                "NotWorkingLinqInterpreter",
            };

            if (RegisterType.IsXUnit)
            {
                // special case when we are using the xunit runner,
                // there is a trait we are not interested in which is
                // the Benchmark one
                var xunitRunner = runner as XUnitTestRunner;
                xunitRunner.AddFilter(XUnitFilter.CreateTraitFilter("Benchmark", "true", true));
            }

            // add category filters if they have been added
            runner.SkipCategories(categories);

            // if we have ignore files, ignore those tests
            var skippedTests = await IgnoreFileParser.ParseContentFilesAsync(NSBundle.MainBundle.BundlePath);

            if (skippedTests.Any())
            {
                // ensure that we skip those tests that have been passed via the ignore files
                runner.SkipTests(skippedTests);
            }

            runner.Run((IList <TestAssemblyInfo>)testAssemblies);
            if (options.EnableXml)
            {
                runner.WriteResultsToFile(writer);
                logger.Info("Xml file was written to the tcp listener.");
            }
            else
            {
                string resultsFilePath = runner.WriteResultsToFile();
                logger.Info($"Xml result can be found {resultsFilePath}");
            }

            logger.Info($"Tests run: {runner.TotalTests} Passed: {runner.PassedTests} Inconclusive: {runner.InconclusiveTests} Failed: {runner.FailedTests} Ignored: {runner.FilteredTests}");
            if (options.TerminateAfterExecution)
            {
                TerminateWithSuccess();
            }
        }
    public void WidgetPerformUpdate(Action <NCUpdateResult> completionHandler)
    {
        var        options = ApplicationOptions.Current;
        TextWriter writer  = null;

        if (!string.IsNullOrEmpty(options.LogFile))
        {
            writer = new StreamWriter(options.LogFile);
        }

        // we generate the logs in two different ways depending if the generate xml flag was
        // provided. If it was, we will write the xml file to the tcp writer if present, else
        // we will write the normal console output using the LogWriter
        var logger = (writer == null || options.EnableXml) ? new LogWriter() : new LogWriter(writer);

        logger.MinimumLogLevel = MinimumLogLevel.Info;
        var testAssemblies = GetTestAssemblies();

        runner = RegisterType.IsXUnit ? (TestRunner) new XUnitTestRunner(logger) : new NUnitTestRunner(logger);
        var categories = RegisterType.IsXUnit ?
                         new List <string> {
            "failing",
            "nonmonotests",
            "outerloop",
            "nonosxtests"
        } :
        new List <string> {
            "MobileNotWorking",
            "NotOnMac",
            "NotWorking",
            "ValueAdd",
            "CAS",
            "InetAccess",
            "NotWorkingLinqInterpreter",
            "BitcodeNotSupported",
        };

        if (RegisterType.IsXUnit)
        {
            // special case when we are using the xunit runner,
            // there is a trait we are not interested in which is
            // the Benchmark one
            var xunitRunner = runner as XUnitTestRunner;
            xunitRunner.AddFilter(XUnitFilter.CreateTraitFilter("Benchmark", "true", true));
        }
        // add category filters if they have been added
        runner.SkipCategories(categories);

        // if we have ignore files, ignore those tests
        var skippedTests = IgnoreFileParser.ParseContentFiles(NSBundle.MainBundle.BundlePath);

        if (skippedTests.Any())
        {
            // ensure that we skip those tests that have been passed via the ignore files
            runner.SkipTests(skippedTests);
        }

        ThreadPool.QueueUserWorkItem((v) =>
        {
            BeginInvokeOnMainThread(() =>
            {
                runner.Run((IList <TestAssemblyInfo>)testAssemblies);
            });
        });

        completionHandler(NCUpdateResult.NewData);
    }