diff options
author | Alan McGovern <alan@xamarin.com> | 2013-07-23 10:29:17 +0400 |
---|---|---|
committer | Alan McGovern <alan@xamarin.com> | 2013-07-23 10:33:33 +0400 |
commit | 4dc929e08402fa5bf80aaf71209e2b8fed892e4e (patch) | |
tree | 17dc7d431fe9676c9efa7978850219eee6f5d792 | |
parent | 51ae5cfcafd5a843cd86a182731472a17121835c (diff) |
Add basic support for outputing on the fly updates
-rw-r--r-- | src/framework/GuiUnit/XmlTestListener.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/framework/GuiUnit/XmlTestListener.cs b/src/framework/GuiUnit/XmlTestListener.cs new file mode 100644 index 0000000..e31286a --- /dev/null +++ b/src/framework/GuiUnit/XmlTestListener.cs @@ -0,0 +1,61 @@ +using System; +using NUnit.Framework.Api; +using System.Xml.Linq; +using System.IO; + +namespace GuiUnit +{ + public class XmlTestListener : ITestListener + { + TextWriter Writer { + get; set; + } + + public XmlTestListener (TextWriter writer) + { + Writer = writer; + } + + public void TestStarted (ITest test) + { + if (test.HasChildren) + Write (new XElement ("suite-started", new XAttribute ("name", test.FullName))); + else + Write (new XElement ("test-started", new XAttribute ("name", test.FullName))); + } + + public void TestFinished (ITestResult result) + { + if (result.Test.HasChildren) + Write (new XElement ("suite-finished", new XAttribute ("name", result.Test.FullName), new XAttribute ("result", ToXmlString (result.ResultState)))); + else + Write (new XElement ("test-finished", new XAttribute ("name", result.Test.FullName), new XAttribute ("result", ToXmlString (result.ResultState)))); + } + + public void TestOutput (TestOutput testOutput) + { + // Ignore + } + + object ToXmlString (ResultState resultState) + { + if (resultState == ResultState.Success) + return "Success"; + else if (resultState == ResultState.Inconclusive) + return "Inconclusive"; + else if (resultState == ResultState.Ignored) + return "Ignored"; + else + return "Failure"; + } + + void Write (XElement element) + { + try { + Writer.WriteLine (element.ToString ()); + } catch { + } + } + } +} + |