NUnit3XmlOutputWriter is responsible for writing the results of a test to a file in NUnit 3.0 format.
Inheritance: NUnitLite.Runner.OutputWriter
Exemplo n.º 1
0
        /// <summary>
        /// Write the result of a test run according to a spec.
        /// </summary>
        /// <param name="result">The test result</param>
        /// <param name="spec">An output specification</param>
        public void WriteResultFile(ITestResult result, OutputSpecification spec)
        {
            string outputPath = Path.Combine(_workDirectory, spec.OutputPath);
            OutputWriter outputWriter = null;

            switch (spec.Format)
            {
                case "nunit3":
                    outputWriter = new NUnit3XmlOutputWriter();
                    break;

                case "nunit2":
                    outputWriter = new NUnit2XmlOutputWriter();
                    break;

                //case "user":
                //    Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
                //    string dir = Path.GetDirectoryName(uri.LocalPath);
                //    outputWriter = new XmlTransformOutputWriter(Path.Combine(dir, spec.Transform));
                //    break;

                default:
                    throw new ArgumentException(
                        string.Format("Invalid XML output format '{0}'", spec.Format),
                        "spec");
            }

            outputWriter.WriteResultFile(result, outputPath);
            Console.WriteLine("Results ({0}) saved as {1}", spec.Format, outputPath);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Write out the result of exploring the tests
        /// </summary>
        /// <param name="test">The top-level test</param>
        /// <param name="spec">An OutputSpecification</param>
        public void WriteTestFile(ITest test, OutputSpecification spec)
        {
            string       outputPath   = Path.Combine(_workDirectory, spec.OutputPath);
            OutputWriter outputWriter = null;

            switch (spec.Format)
            {
            case "nunit3":
                outputWriter = new NUnit3XmlOutputWriter();
                break;

            case "cases":
                outputWriter = new TestCaseOutputWriter();
                break;

            //case "user":
            //    Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            //    string dir = Path.GetDirectoryName(uri.LocalPath);
            //    outputWriter = new XmlTransformOutputWriter(Path.Combine(dir, spec.Transform));
            //    break;

            default:
                throw new ArgumentException(
                          string.Format("Invalid XML output format '{0}'", spec.Format),
                          "spec");
            }

            outputWriter.WriteTestFile(test, outputPath);
            Console.WriteLine("Tests ({0}) saved as {1}", spec.Format, outputPath);
        }
        protected virtual void PublishResults(TestResult testResults)
        {
            TestResultsConfig.PrintConfig();

              Log.Info(this.tag, "Publishing results : " + DateTime.Now +
                    "\nTotal count : {0}, Failed : {1}",
            testResults.AssertCount,
            testResults.FailCount);

              if (TestResultsConfig.IsRemote)
              {
            switch (TestResultsConfig.TestsResultsFormat)
            {
              case "plain_text":
            //          We already published test results because in this case we publish each test results separately. See SetTextWriterForAndroidTestRunner() method.
            return;
              case "nunit2":
            var nunit2Writer = new NUnit2XmlOutputWriter(this.testsStartTime);
            var tcpwriter = this.NetworkWriter;

            nunit2Writer.WriteResultFile(testResults, tcpwriter);
            tcpwriter.Close();

            Log.Info(this.tag, "Published tests results in nunit2 format");
            return;
              case "nunit3":
            var nunit3Writer = new NUnit3XmlOutputWriter(this.testsStartTime);
            var newtworkWriter = this.NetworkWriter;

            nunit3Writer.WriteResultFile(testResults, newtworkWriter);
            newtworkWriter.Close();

            Log.Info(this.tag, "Published tests results in nunit3 format");
            return;
            }
              }
              else
              {
            //      If we don't need to send test results to remote server, just return.
            return;
              }
        }