Ejemplo n.º 1
0
 /// <summary>
 /// Saves the TestResult as xml to the specified path.
 /// </summary>
 /// <param name="result">The test result to be saved.</param>
 /// <param name="textWriter">The text writer.</param>
 public static void SaveXmlOutput(TestResult result, TextWriter textWriter)
 {
     if (textWriter != null)
     {
         var writer = new XmlResultWriter(textWriter);
         writer.SaveTestResult(result);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Saves the TestResult as xml to the specified path.
 /// </summary>
 /// <param name="result">The test result to be saved.</param>
 /// <param name="outputXmlPath">The output xml path.</param>
 private static void SaveXmlOutput(TestResult result, string outputXmlPath)
 {
     if (!string.IsNullOrEmpty(outputXmlPath))
     {
         var writer = new XmlResultWriter(outputXmlPath);
         writer.SaveTestResult(result);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs all tests</summary>
        /// <param name="displayName">Name of the test, which is normally the executing
        /// assembly's Location.</param>
        /// <returns>0 if tests ran successfully, a negative number otherwise</returns>
        public static int RunAllTests(string displayName)
        {
            TestRunner runner = MakeTestRunner(displayName);
            string category = ParseTestCategory();
            runner.Run(new UnitTestListener(), new TestFilter(category));
            XmlResultWriter writer = new XmlResultWriter("TestResult.xml");
            writer.SaveTestResult(runner.TestResult);

            XslCompiledTransform xsl = new XslCompiledTransform();
            xsl.Load("Resources/NUnitToJUnit.xslt");
            xsl.Transform("TestResult.xml", "TestResult.JUnit.xml");

            if (runner.TestResult.IsFailure)
                return -1;

            return 0;
        }
Ejemplo n.º 4
0
			public override void RunFinished(TestResult result)
			{
				base.RunFinished (result);

				var resultWriter = new XmlResultWriter (_runOptions.XmlResultsPath);
				resultWriter.SaveTestResult (result);

				if (_runOptions.PerformXslTransform) {
					var transform = new XslTransform ();
					transform.Load (_runOptions.XslTransformPath);
					transform.Transform (
						_runOptions.XmlResultsPath,
						_runOptions.TransformedResultsPath);
				}

				File.WriteAllText (_runOptions.StdoutPath, StdoutStandin.ToString ());

				//if (runOptions.PerformXslTransform && runOptions.ShouldLaunchResults)
				//	System.Diagnostics.Process.Start (runOptions.TransformedResultsPath);

				File.WriteAllText("status.txt", "finished");
			}
Ejemplo n.º 5
0
        private void OnRunTest(string testDll)
        {
            string originalDllName = testDll;
             LinkedWindow.Close();
             // Shadow copy to temp folder
             string tempFile = Path.GetTempFileName();
             tempFile = tempFile.Replace(Path.GetExtension(tempFile), Path.GetExtension(testDll));
             File.Copy(testDll, tempFile, true);

             //Copy the PDB to get stack trace
             string destPdbFile = tempFile.Replace(Path.GetExtension(tempFile), ".pdb");
             string srcPdb = testDll.Replace(Path.GetExtension(testDll), ".pdb");
             File.Copy(srcPdb, destPdbFile, true);

             testDll = tempFile;

             // Copy Moq.dll and dependencies to temp folder
             CopyRequiredLibsToTemp(tempFile);

             SimpleTestFilter filter = new SimpleTestFilter(DLLs.FirstOrDefault(d => d.FullPath == originalDllName).Tests);
             TestResult testResult = RunTestsInAssemblies(new List<string>() { testDll }, filter);

             // Save the result to xml file:
             string resultFile = Path.GetDirectoryName(testDll) + @"\TestResult.xml";
             XmlResultWriter resultWriter = new XmlResultWriter(resultFile);
             resultWriter.SaveTestResult(testResult);

             // show results dialog
             string extraMsg = "Result file can be found at " + resultFile;
             TestResultViewerViewModel vm = new TestResultViewerViewModel(testResult, extraMsg);
             TestResultViewer viewer = new TestResultViewer(vm);
             //viewer.Owner = LinkedWindow;
             GeneralHelper.SetRevitAsWindowOwner(viewer);
             viewer.ShowDialog();

             // cleanup
             File.Delete(tempFile);
             File.Delete(destPdbFile);
        }
Ejemplo n.º 6
0
        private void OnRunAllTests()
        {
            LinkedWindow.Close();

             List<string> copiedAssemblies = new List<string>();

             foreach (TestableDll dll in DLLs)
             {
            // Shadow copy to temp folder
            string tempFile = Path.GetTempFileName();
            tempFile = tempFile.Replace(Path.GetExtension(tempFile), Path.GetExtension(dll.FullPath));
            File.Copy(dll.FullPath, tempFile, true);

            //Copy the PDB to get stack trace
            string destPdbFile = tempFile.Replace(Path.GetExtension(tempFile), ".pdb");
            string srcPdb = dll.FullPath.Replace(Path.GetExtension(dll.FullPath), ".pdb");
            File.Copy(srcPdb, destPdbFile, true);

            copiedAssemblies.Add(tempFile);
             }

             // Copy Moq.dll and dependencies to temp folder
             CopyRequiredLibsToTemp(DLLs.First().FullPath);

             TestResult testResult = RunTestsInAssemblies(copiedAssemblies, TestFilter.Empty);

             // Save the result to xml file:
             string resultFile = Path.GetDirectoryName(DLLs.First().FullPath) + @"\TestResult.xml";
             XmlResultWriter resultWriter = new XmlResultWriter(resultFile);
             resultWriter.SaveTestResult(testResult);

             // show results dialog
             string extraMsg = "Result file can be found at " + resultFile;
             TestResultViewerViewModel vm = new TestResultViewerViewModel(testResult, extraMsg);
             TestResultViewer viewer = new TestResultViewer(vm);
             //viewer.Owner = LinkedWindow;
             GeneralHelper.SetRevitAsWindowOwner(viewer);
             viewer.ShowDialog();

             // cleanup
             foreach (string dll in copiedAssemblies)
             {
            File.Delete(dll);
            File.Delete(Path.ChangeExtension(dll, ".pdb"));
             }
        }
Ejemplo n.º 7
0
        public void RunFinished(TestResult result)
        {
            // Reset console output
            consoleStringWriter.Dispose();
            var consoleOut = Console.Out;
            Console.SetOut(consoleOut);

            // Write the TestResult.xml
            if (testresultpath != null)
            {
                var testResultBuilder = new StringBuilder();
                using (var writer = new StringWriter(testResultBuilder))
                {
                    var xmlWriter = new XmlResultWriter(writer);
                    xmlWriter.SaveTestResult(result);
                }

                var xmlOutput = testResultBuilder.ToString();
                using (var writer = new StreamWriter(testresultpath))
                {
                    writer.Write(xmlOutput);
                }
            }
        }
Ejemplo n.º 8
0
        private void FormatResult(NUnit2Test testElement, TestResult result)
        {
            // temp file for storing test results
            string xmlResultFile = Path.GetTempFileName();

            try {
                XmlResultWriter resultWriter = new XmlResultWriter(xmlResultFile);
                resultWriter.SaveTestResult(result);

                foreach (FormatterElement formatter in FormatterElements) {
                    // permanent file for storing test results
                    string outputFile = result.Name + "-results" + formatter.Extension;

                    if (formatter.Type == FormatterType.Xml) {
                        if (formatter.UseFile) {

                            if (formatter.OutputDirectory != null) {
                                // ensure output directory exists
                                if (!formatter.OutputDirectory.Exists) {
                                    formatter.OutputDirectory.Create();
                                }

                                // combine output directory and result filename
                                outputFile = Path.Combine(formatter.OutputDirectory.FullName,
                                    Path.GetFileName(outputFile));
                            }

                            // copy the temp result file to permanent location
                            File.Copy(xmlResultFile, outputFile, true);
                        } else {
                            using (StreamReader reader = new StreamReader(xmlResultFile)) {
                                // strip off the xml header
                                reader.ReadLine();
                                StringBuilder builder = new StringBuilder();
                                while (reader.Peek() > -1) {
                                    builder.Append(reader.ReadLine().Trim()).Append(
                                        Environment.NewLine);
                                }
                                Log(Level.Info, builder.ToString());
                            }
                        }
                    } else if (formatter.Type == FormatterType.Plain) {
                        TextWriter writer;
                        if (formatter.UseFile) {

                            if (formatter.OutputDirectory != null) {
                                // ensure output directory exists
                                if (!formatter.OutputDirectory.Exists) {
                                    formatter.OutputDirectory.Create();
                                }

                                // combine output directory and result filename
                                outputFile = Path.Combine(formatter.OutputDirectory.FullName,
                                    Path.GetFileName(outputFile));
                            }

                            writer = new StreamWriter(outputFile);
                        } else {
                            writer = new LogWriter(this, Level.Info, CultureInfo.InvariantCulture);
                        }
                        CreateSummaryDocument(xmlResultFile, writer, testElement);
                        writer.Close();
                    }
                }
            } catch (Exception ex) {
                throw new BuildException("Test results could not be formatted.",
                    Location, ex);
            } finally {
                // make sure temp file with test results is removed
                File.Delete(xmlResultFile);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public static void RunMain(string [] args)
        {
            bool launchResults = true;
            bool performXslTransform = true;
            bool showHelp = false;

            var directory = Directory.GetCurrentDirectory ();

            string xmlResultsFile = Path.Combine (directory, "test_results.xml");
            string transformedResultsFile = Path.Combine (directory, "test_results.html");
            string xslTransformPath = Path.Combine ("Resources", "tests.xsl");
            string stdoutFile = Path.Combine (directory, "stdout.txt");
            var filters = new List<RegexFilter> ();
            var optionSet = new OptionSet () {
                { "i|include=", x => filters.Add(RegexFilter.Parse(x, FilterAction.Include)) },
                { "x|exclude=", x => filters.Add(RegexFilter.Parse(x, FilterAction.Exclude)) },
                { "no-launch-results", x => launchResults = false },
                { "no-xsl-transform", x => performXslTransform = false },
                { "xml-results=", x => xmlResultsFile = x },
                { "xsl-transform=", x => xslTransformPath = x },
                { "transformed-results=", x => transformedResultsFile = x },
                { "stdout=", x => stdoutFile = x },
            //				{ "v|verbose",  x => ++verbose },
                { "h|?|help",   x => showHelp = true },
            };

            List<string> extra = optionSet.Parse (args);
            if (extra.Count > 0)
                Console.WriteLine (
                    "Ignoring {0} unrecognized argument(s): {1}",
                    extra.Count, string.Join (", ", extra));

            if (showHelp) {
                ShowHelp (optionSet);
                System.Threading.Thread.Sleep (3000);
                return;
            }

            CoreExtensions.Host.InitializeService ();

            var assembly = Assembly.GetExecutingAssembly ();

            var simpleTestRunner = new SimpleTestRunner ();
            TestPackage package = new TestPackage (assembly.GetName ().Name);
            package.Assemblies.Add (assembly.Location);
            if (!simpleTestRunner.Load (package)) {
                Console.WriteLine ("Could not find the tests.");
                return;
            }

            var cli = new CommandLineInterface (filters);

            var result = simpleTestRunner.Run (cli, cli);

            var resultWriter = new XmlResultWriter (xmlResultsFile);
            resultWriter.SaveTestResult (result);

            if (performXslTransform) {
                var transform = new XslTransform ();
                transform.Load (xslTransformPath);
                transform.Transform (xmlResultsFile, transformedResultsFile);
            }

            File.WriteAllText (stdoutFile, cli._stdoutStandin.ToString ());

            if (performXslTransform && launchResults)
                System.Diagnostics.Process.Start (transformedResultsFile);
        }
Ejemplo n.º 11
0
 public void RunFinished(TestResult result)
 {
     try
     {
         var writer = new XmlResultWriter(_outputXmlFile);
         writer.SaveTestResult(result);
     }
     finally
     {
         //Finished
         MarkAsFinished();
     }
 }