Inheritance: ITestFilter
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, IDictionary runSettings, TestFilter filter)
        {
            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, runSettings, filter);
            Console.WriteLine("Results ({0}) saved as {1}", spec.Format, outputPath);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Writes a test result to a file
 /// </summary>
 /// <param name="result">The result to be written</param>
 /// <param name="outputPath">Path to the file to which the result is written</param>
 /// <param name="runSettings">A dictionary of settings used for this test run</param>
 public void WriteResultFile(ITestResult result, string outputPath, IDictionary runSettings, TestFilter filter)
 {
     using (StreamWriter writer = new StreamWriter(outputPath, false, Encoding.UTF8))
     {
         WriteResultFile(result, writer, runSettings, filter);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Writes the result of a test run to a specified TextWriter.
 /// </summary>
 /// <param name="result">The test result for the run</param>
 /// <param name="writer">The TextWriter to which the xml will be written</param>
 /// <param name="runSettings"></param>
 /// <param name="filter"></param>
 public override void WriteResultFile(ITestResult result, TextWriter writer, IDictionary<string, object> runSettings, TestFilter filter)
 {
     var settings = new XmlWriterSettings { Indent = true };
     using (var xmlWriter = XmlWriter.Create(writer, settings))
     {
         WriteXmlOutput(result, xmlWriter);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Writes a test result to a file
 /// </summary>
 /// <param name="result">The result to be written</param>
 /// <param name="outputPath">Path to the file to which the result is written</param>
 /// <param name="runSettings">A dictionary of settings used for this test run</param>
 public void WriteResultFile(ITestResult result, string outputPath, IDictionary<string, object> runSettings, TestFilter filter)
 {
     using (var stream = new FileStream(outputPath, FileMode.Create))
     using (var writer = new StreamWriter(stream, Encoding.UTF8))
     {
         WriteResultFile(result, writer, runSettings, filter);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Writes the test result to the specified TextWriter
        /// </summary>
        /// <param name="result">The result to be written to a file</param>
        /// <param name="writer">A TextWriter to which the result is written</param>
        public override void WriteResultFile(ITestResult result, TextWriter writer, IDictionary runSettings, TestFilter filter)
        {
            XmlWriterSettings xmlSettings = new XmlWriterSettings();
            xmlSettings.Indent = true;

            using (XmlWriter xmlWriter = XmlWriter.Create(writer, xmlSettings))
            {
                WriteXmlResultOutput(result, xmlWriter, runSettings, filter);
            }
        }
Exemplo n.º 6
0
        private ITestResult runTests(string nameSpace, TestFilter filter)
        {
            IDictionary options = new Hashtable();
            if (nameSpace != null)
                options["LOAD"] = new string[] { nameSpace };

            if (runner.Load(testAssembly, options))
                return runner.Run(TestListener.NULL, filter);

            return null;
        }
Exemplo n.º 7
0
        private ITestResult runTests(string nameSpace, TestFilter filter)
        {
            IDictionary<string, object> options = new Dictionary<string, object>();
            if (nameSpace != null)
                options["LOAD"] = new string[] { nameSpace };
            // No need for the overhead of parallel execution here
            options["NumberOfTestWorkers"] = 0;

            if (runner.Load(testAssembly, options) != null)
                return runner.Run(TestListener.NULL, filter);

            return null;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes the result of a test run to a specified TextWriter.
        /// </summary>
        /// <param name="result">The test result for the run</param>
        /// <param name="writer">The TextWriter to which the xml will be written</param>
        /// <param name="runSettings"></param>
        /// <param name="filter"></param>
        public override void WriteResultFile(ITestResult result, TextWriter writer, IDictionary<string, object> runSettings, TestFilter filter)
        {
            // NOTE: Under .NET 1.1, XmlTextWriter does not implement IDisposable,
            // but does implement Close(). Hence we cannot use a 'using' clause.
            //using (XmlTextWriter xmlWriter = new XmlTextWriter(writer))
            XmlTextWriter xmlWriter = new XmlTextWriter(writer);
            xmlWriter.Formatting = Formatting.Indented;

            try
            {
                WriteXmlOutput(result, xmlWriter);
            }
            finally
            {
                writer.Close();
            }
        }
Exemplo n.º 9
0
        private void WriteXmlResultOutput(ITestResult result, XmlWriter xmlWriter, IDictionary<string, object> runSettings, TestFilter filter)
        {
            TNode resultNode = result.ToXml(true);

            // Insert elements as first child in reverse order
            if (runSettings != null) // Some platforms don't have settings
                FrameworkController.InsertSettingsElement(resultNode, runSettings);
            FrameworkController.InsertEnvironmentElement(resultNode);

            TNode testRun = MakeTestRunElement(result);

            testRun.ChildNodes.Add(MakeCommandLineElement());
            testRun.ChildNodes.Add(MakeTestFilterElement(filter));
            testRun.ChildNodes.Add(resultNode);

            testRun.WriteTo(xmlWriter);
        }
Exemplo n.º 10
0
        public int RunTests(TestFilter filter, IDictionary runSettings)
        {
            var startTime = DateTime.UtcNow;

            ITestResult result = _runner.Run(this, filter);

#if SILVERLIGHT
            // Silverlight can't display results while the test is running
            // so we do it afterwards.
            foreach(ITestResult testResult in _results)
                _textUI.TestFinished(testResult);
#endif
            ReportResults(result);

#if !SILVERLIGHT && !PORTABLE
            if (_options.ResultOutputSpecifications.Count > 0)
            {
                var outputManager = new OutputManager(_options.WorkDirectory);

                foreach (var spec in _options.ResultOutputSpecifications)
                    outputManager.WriteResultFile(result, spec, runSettings, filter);
            }
#endif

            return Summary.FailureCount + Summary.ErrorCount + Summary.InvalidCount;
        }
Exemplo n.º 11
0
        static void ChainCategoryFilter(IEnumerable <string> categories, bool negate, ref TestFilter chain)
        {
            bool gotCategories = false;
            if (categories != null) {
                var filter = new CategoryFilter ();
                foreach (string c in categories) {
                    Log.Info (TAG, "  {0}", c);
                    filter.AddCategory (c);
                    gotCategories = true;
                }

                chain = new AndFilter (chain, negate ? (TestFilter)new NotFilter (filter) : (TestFilter)filter);
            }

            if (!gotCategories)
                Log.Info (TAG, "  none");
        }
Exemplo n.º 12
0
        public int RunTests(TestFilter filter, IDictionary<string, object> runSettings)
        {
            var startTime = DateTime.UtcNow;

            ITestResult result = _runner.Run(this, filter);
            
            ReportResults(result);

#if !PORTABLE
            if (_options.ResultOutputSpecifications.Count > 0)
            {
                var outputManager = new OutputManager(_options.WorkDirectory);

                foreach (var spec in _options.ResultOutputSpecifications)
                    outputManager.WriteResultFile(result, spec, runSettings, filter);
            }
#endif
            if (Summary.InvalidTestFixtures > 0)
                return INVALID_TEST_FIXTURE;

            return Summary.FailureCount + Summary.ErrorCount + Summary.InvalidCount;
        }
Exemplo n.º 13
0
 private static TNode MakeTestFilterElement(TestFilter filter)
 {
     TNode result = new TNode("filter");
     if (!filter.IsEmpty)
         filter.AddToXml(result, true);
     return result;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Abstract method that writes a test result to a TextWriter
 /// </summary>
 /// <param name="result">The result to be written</param>
 /// <param name="writer">A TextWriter to which the result is written</param>
 /// <param name="runSettings">A dictionary of settings used for this test run</param>
 /// <param name="filter"></param>
 public abstract void WriteResultFile(ITestResult result, TextWriter writer, IDictionary<string, object> runSettings, TestFilter filter);
Exemplo n.º 15
0
 /// <summary>
 /// Write a list of test cases to a file
 /// </summary>
 /// <param name="result"></param>
 /// <param name="writer"></param>
 /// <param name="runSettings"></param>
 /// <param name="filter"></param>
 public override void WriteResultFile(ITestResult result, TextWriter writer, IDictionary<string, object> runSettings, TestFilter filter)
 {
     WriteTestFile(result.Test, writer);
 }