Ejemplo n.º 1
0
        public static MainArgs ValueOf(string[] args)
        {
            Dictionary <string, string> values = new Dictionary <string, string>();

            if (args != null && args.Length > 0)
            {
                foreach (string s in args)
                {
                    string[] ss = s.Split('=');
                    if (ss.Length != 2)
                    {
                        continue;
                    }
                    string key   = ss[0].Trim();
                    string value = ss[1].Trim();
                    values[key] = value;
                }
            }
            MainArgs a = new MainArgs {
                values = values
            };

            return(a);
        }
Ejemplo n.º 2
0
        public static void Run(string loc, string[] args)
        {
            MainArgs ma       = MainArgs.ValueOf(args);
            string   excludes = ma.Get("exclude", null);
            string   includes = ma.Get("include", null);
            string   outfile  = ma.Get("out", "TestResult.xml");

            CoreExtensions.Host.InitializeService();
            TestSuiteBuilder builder          = new TestSuiteBuilder();
            TestPackage      testPackage      = new TestPackage(loc);
            RemoteTestRunner remoteTestRunner = new RemoteTestRunner();

            remoteTestRunner.Load(testPackage);
            TestSuite          suite    = builder.Build(testPackage);
            TestSuite          root     = suite.Tests[0] as TestSuite;
            List <TestFixture> fixtures = new List <TestFixture>();

            ScanFixtures(root, fixtures);
            Console.WriteLine("--------------- {0} TextFixtures --------------- \n", fixtures.Count);
            //TestName testName = ((TestMethod) ((TestFixture) test.Tests[0]).Tests[0]).MethodName;

            ITestFilter filter     = null;
            bool        hasInclude = !string.IsNullOrEmpty(includes);
            bool        hasExclude = !string.IsNullOrEmpty(excludes);

            if (hasInclude)
            {
                if (hasExclude)
                {
                    // incldue+exclude; exclude first
                    filter =
                        new AndFilter(new ITestFilter[]
                                      { new NotFilter(new CategoryFilter(excludes.Split(','))), new SimpleNameFilter(includes.Split(',')), });
                }
                else
                {
                    // include
                    filter = new SimpleNameFilter(includes.Split(','));
                }
            }
            else // no include
            {
                if (hasExclude)
                {
                    // Only exclude
                    filter = new NotFilter(new CategoryFilter(excludes.Split(',')));
                }
                else
                {
                    // none
                    filter = new TrueFilter();
                }
            }

            int              succCnt = 0, failCnt = 0, errorCnt = 0, assertCnt = 0;
            TestResult       tr       = new TestResult(new TestName());
            RunEventListener eventLsn = new RunEventListener();

            foreach (TestFixture tf in fixtures)
            {
                TestResult    result = tf.Run(eventLsn, filter);
                FixtureResult fr     = null;
                if (result.Results != null)
                {
                    fr         = new FixtureResult(result);
                    succCnt   += fr.succCnt;
                    failCnt   += fr.failCnt;
                    errorCnt  += fr.errorCnt;
                    assertCnt += fr.assertCnt;
                    Console.WriteLine("  Done: " + fr.ToString());
                }
                else
                {
                    Console.WriteLine("  Done: no result.");
                }
                tr.AddResult(result);
            }
            if (failCnt + errorCnt == 0)
            {
                Console.WriteLine(
                    @"=========================================
Test Success! Cases: {0}, asserts: {1}
=========================================",
                    succCnt, assertCnt);
            }
            else
            {
                Console.WriteLine(
                    @"=================================================================================
 Test with errors: Cases: {0}, asserts: {4}, Succ: {1}, fail:{2}, error: {3}
=================================================================================",
                    succCnt + errorCnt + failCnt, succCnt, failCnt, errorCnt, assertCnt);
            }
            XmlResultWriter w = new XmlResultWriter(outfile);

            w.SaveTestResult(tr);
            Console.WriteLine("Result save to: {0}", outfile);
        }