コード例 #1
0
        public ConsoleRunner(CommandLineOptions commandlineOptions)
        {
            this.options = commandlineOptions;

            string    assemblyPath = Path.GetFullPath(options.AssemblyName);
            AppDomain testDomain   = AppDomain.CurrentDomain;

            if (options.RunInSeparateAppDomain)
            {
                testDomain = CreateDomain(Path.GetDirectoryName(assemblyPath));
            }

            var driverSettings = options.CreateDriverSettings();

            this.driver = new FrameworkDriver(assemblyPath, testDomain, driverSettings);

            this.workDirectory = options.WorkDirectory;
            if (this.workDirectory == null)
            {
                this.workDirectory = Environment.CurrentDirectory;
            }
            else if (!Directory.Exists(this.workDirectory))
            {
                Directory.CreateDirectory(this.workDirectory);
            }
        }
コード例 #2
0
        private int ExploreTests(FrameworkDriver driver, string filter)
        {
            IDictionary settings = new Dictionary <string, object>();

            XmlNode testNode = driver.ExploreTests(filter);

            if (testNode.Name == "error")
            {
                DisplayUnexpectedErrorMessage(testNode);
                return(ConsoleRunner.UNEXPECTED_ERROR);
            }

            if (testNode.Attributes["runstate"].Value == "NotRunnable")
            {
                DisplayNotRunnableMessage(testNode);
                return(ConsoleRunner.FILE_NOT_FOUND);
            }

            string        exploreFile = options.ExploreFile;
            XmlTextWriter testWriter  = exploreFile != null && exploreFile.Length > 0
                ? new XmlTextWriter(Path.Combine(workDirectory, exploreFile), System.Text.Encoding.UTF8)
                : new XmlTextWriter(Console.Out);

            testWriter.Formatting = Formatting.Indented;
            testNode.WriteTo(testWriter);
            testWriter.Close();

            if (exploreFile != null)
            {
                Console.WriteLine("Tests saved as {0}", options.ExploreFile);
            }

            return(ConsoleRunner.OK);
        }
コード例 #3
0
        public ConsoleRunner(CommandLineOptions commandlineOptions)
        {
            this.options = commandlineOptions;

            string assemblyPath = Path.GetFullPath(options.AssemblyName);
            AppDomain testDomain = AppDomain.CurrentDomain;
            if (options.RunInSeparateAppDomain)
                testDomain = CreateDomain(Path.GetDirectoryName(assemblyPath));

            var driverSettings = options.CreateDriverSettings();
            this.driver = new FrameworkDriver(assemblyPath, testDomain, driverSettings);

            this.workDirectory = options.WorkDirectory;
            if (this.workDirectory == null)
                this.workDirectory = Environment.CurrentDirectory;
            else if (!Directory.Exists(this.workDirectory))
                Directory.CreateDirectory(this.workDirectory);
        }
コード例 #4
0
        private int RunTests(FrameworkDriver driver, string testFilter)
        {
            XmlNode loadReport = driver.Load();
            if (loadReport.Name == "error")
            {
                DisplayUnexpectedErrorMessage(loadReport);
                return ConsoleRunner.UNEXPECTED_ERROR;
            }

            TextWriter savedOut = Console.Out;
            TextWriter savedError = Console.Error;
            XmlNode resultNode;

            try
            {
                if (options.OutFile != null)
                    Console.SetOut(new StreamWriter(Path.Combine(workDirectory, options.OutFile)));

                if (options.ErrFile != null)
                    Console.SetError(new StreamWriter(Path.Combine(workDirectory, options.ErrFile)));

                resultNode = driver.Run(testFilter);
            }
            finally
            {
                Console.Out.Flush();
                Console.SetOut(savedOut);
                Console.Error.Flush();
                Console.SetError(savedError);
            }

            if (resultNode.Name == "error")
            {
                DisplayUnexpectedErrorMessage(resultNode);
                return ConsoleRunner.UNEXPECTED_ERROR;
            }

            if (resultNode.Attributes["runstate"].Value == "NotRunnable")
            {
                DisplayNotRunnableMessage(resultNode);
                return ConsoleRunner.FILE_NOT_FOUND;
            }

            string v3ResultFile = Path.Combine(workDirectory, options.V3ResultFile);
            NUnit3TestResultWriter nunit3ResultWriter = new NUnit3TestResultWriter();
            nunit3ResultWriter.WriteResultFile(resultNode, v3ResultFile);
            //XmlTextWriter nunit3ResultWriter = new XmlTextWriter(v3ResultFile, System.Text.Encoding.UTF8);
            //nunit3ResultWriter.Formatting = Formatting.Indented;
            //resultNode.WriteTo(nunit3ResultWriter);
            //nunit3ResultWriter.Close();

            string v2ResultFile = Path.Combine(workDirectory, options.V2ResultFile);
            NUnit2TestResultWriter nunit2ResultWriter = new NUnit2TestResultWriter();
            nunit2ResultWriter.WriteResultFile(resultNode, v2ResultFile);

            if (!options.DisplayTeamCityServiceMessages)
                new ResultReporter(resultNode).ReportResults();

            if (options.OutFile != null)
                Console.WriteLine("Test standard output saved as {0}", Path.Combine(workDirectory, options.OutFile));
            if (options.ErrFile != null)
                Console.WriteLine("Test error output saved as {0}", Path.Combine(workDirectory, options.ErrFile));
            Console.WriteLine("NUnit3 Result File Saved as {0}", v3ResultFile);
            Console.WriteLine("NUnit2 Result File Saved as {0}", v2ResultFile);

            return int.Parse(resultNode.Attributes["failed"].Value);
        }
コード例 #5
0
        private int ExploreTests(FrameworkDriver driver, string filter)
        {
            IDictionary settings = new Dictionary<string, object>();

            XmlNode testNode = driver.ExploreTests(filter);

            if (testNode.Name == "error")
            {
                DisplayUnexpectedErrorMessage(testNode);
                return ConsoleRunner.UNEXPECTED_ERROR;
            }

            if (testNode.Attributes["runstate"].Value == "NotRunnable")
            {
                DisplayNotRunnableMessage(testNode);
                return ConsoleRunner.FILE_NOT_FOUND;
            }

            string exploreFile = options.ExploreFile;
            XmlTextWriter testWriter = exploreFile != null && exploreFile.Length > 0
                ? new XmlTextWriter(Path.Combine(workDirectory, exploreFile), System.Text.Encoding.UTF8)
                : new XmlTextWriter(Console.Out);
            testWriter.Formatting = Formatting.Indented;
            testNode.WriteTo(testWriter);
            testWriter.Close();

            if (exploreFile != null)
                Console.WriteLine("Tests saved as {0}", options.ExploreFile);

            return ConsoleRunner.OK;
        }
コード例 #6
0
        private int RunTests(FrameworkDriver driver, string testFilter)
        {
            XmlNode loadReport = driver.Load();

            if (loadReport.Name == "error")
            {
                DisplayUnexpectedErrorMessage(loadReport);
                return(ConsoleRunner.UNEXPECTED_ERROR);
            }

            TextWriter savedOut   = Console.Out;
            TextWriter savedError = Console.Error;
            XmlNode    resultNode;

            try
            {
                if (options.OutFile != null)
                {
                    Console.SetOut(new StreamWriter(Path.Combine(workDirectory, options.OutFile)));
                }

                if (options.ErrFile != null)
                {
                    Console.SetError(new StreamWriter(Path.Combine(workDirectory, options.ErrFile)));
                }

                resultNode = driver.Run(testFilter);
            }
            finally
            {
                Console.Out.Flush();
                Console.SetOut(savedOut);
                Console.Error.Flush();
                Console.SetError(savedError);
            }

            if (resultNode.Name == "error")
            {
                DisplayUnexpectedErrorMessage(resultNode);
                return(ConsoleRunner.UNEXPECTED_ERROR);
            }

            if (resultNode.Attributes["runstate"].Value == "NotRunnable")
            {
                DisplayNotRunnableMessage(resultNode);
                return(ConsoleRunner.FILE_NOT_FOUND);
            }

            string v3ResultFile = Path.Combine(workDirectory, options.V3ResultFile);
            NUnit3TestResultWriter nunit3ResultWriter = new NUnit3TestResultWriter();

            nunit3ResultWriter.WriteResultFile(resultNode, v3ResultFile);
            //XmlTextWriter nunit3ResultWriter = new XmlTextWriter(v3ResultFile, System.Text.Encoding.UTF8);
            //nunit3ResultWriter.Formatting = Formatting.Indented;
            //resultNode.WriteTo(nunit3ResultWriter);
            //nunit3ResultWriter.Close();

            string v2ResultFile = Path.Combine(workDirectory, options.V2ResultFile);
            NUnit2TestResultWriter nunit2ResultWriter = new NUnit2TestResultWriter();

            nunit2ResultWriter.WriteResultFile(resultNode, v2ResultFile);

            if (!options.DisplayTeamCityServiceMessages)
            {
                new ResultReporter(resultNode).ReportResults();
            }

            if (options.OutFile != null)
            {
                Console.WriteLine("Test standard output saved as {0}", Path.Combine(workDirectory, options.OutFile));
            }
            if (options.ErrFile != null)
            {
                Console.WriteLine("Test error output saved as {0}", Path.Combine(workDirectory, options.ErrFile));
            }
            Console.WriteLine("NUnit3 Result File Saved as {0}", v3ResultFile);
            Console.WriteLine("NUnit2 Result File Saved as {0}", v2ResultFile);

            return(OK);
        }