[XHarness] Add NUnit3 support to the old bcl tests. (#7846)
Move the old bcl tests based on NUnit to use the NUnit V3 output so that we can add logs to the vsts imported tests. Follow up of PR: https://github.com/xamarin/xamarin-macios/pull/7844
This commit is contained in:
Родитель
1a0b2bbcc0
Коммит
4544fb8fcd
|
@ -101,9 +101,6 @@
|
|||
<Compile Include="templates\common\TestRunner.NUnit\ClassOrNamespaceFilter.cs">
|
||||
<Link>TestRunner.NUnit\ClassOrNamespaceFilter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.NUnit\XmlOutputWriter.cs">
|
||||
<Link>TestRunner.NUnit\XmlOutputWriter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.NUnit\TestMethodFilter.cs">
|
||||
<Link>TestRunner.NUnit\TestMethodFilter.cs</Link>
|
||||
</Compile>
|
||||
|
@ -146,9 +143,6 @@
|
|||
<Compile Include="templates\common\TestRunner.xUnit\XUnitFilterType.cs">
|
||||
<Link>TestRunner.xUnit\XUnitFilterType.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitResultFileFormat.cs">
|
||||
<Link>TestRunner.xUnit\XUnitResultFileFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitTestRunner.cs">
|
||||
<Link>TestRunner.xUnit\XUnitTestRunner.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -176,9 +176,6 @@
|
|||
<Compile Include="templates\common\TestRunner.NUnit\TestMethodFilter.cs">
|
||||
<Link>TestRunner.NUnit\TestMethodFilter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.NUnit\XmlOutputWriter.cs">
|
||||
<Link>TestRunner.NUnit\XmlOutputWriter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.Core\Extensions.Bool.cs">
|
||||
<Link>TestRunner.Core\Extensions.Bool.cs</Link>
|
||||
</Compile>
|
||||
|
@ -218,9 +215,6 @@
|
|||
<Compile Include="templates\common\TestRunner.xUnit\XUnitFilterType.cs">
|
||||
<Link>TestRunner.xUnit\XUnitFilterType.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitResultFileFormat.cs">
|
||||
<Link>TestRunner.xUnit\XUnitResultFileFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitTestRunner.cs">
|
||||
<Link>TestRunner.xUnit\XUnitTestRunner.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -206,18 +206,12 @@
|
|||
<Compile Include="templates\common\TestRunner.NUnit\TestMethodFilter.cs">
|
||||
<Link>TestRunner.NUnit\TestMethodFilter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.NUnit\XmlOutputWriter.cs">
|
||||
<Link>TestRunner.NUnit\XmlOutputWriter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitFilter.cs">
|
||||
<Link>TestRunner.xUnit\XUnitFilter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitFilterType.cs">
|
||||
<Link>TestRunner.xUnit\XUnitFilterType.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitResultFileFormat.cs">
|
||||
<Link>TestRunner.xUnit\XUnitResultFileFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitTestRunner.cs">
|
||||
<Link>TestRunner.xUnit\XUnitTestRunner.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -189,9 +189,6 @@
|
|||
<Compile Include="templates\common\TestRunner.NUnit\TestMethodFilter.cs">
|
||||
<Link>TestRunner.NUnit\TestMethodFilter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.NUnit\XmlOutputWriter.cs">
|
||||
<Link>TestRunner.NUnit\XmlOutputWriter.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.Core\Extensions.Bool.cs">
|
||||
<Link>TestRunner.Core\Extensions.Bool.cs</Link>
|
||||
</Compile>
|
||||
|
@ -231,9 +228,6 @@
|
|||
<Compile Include="templates\common\TestRunner.xUnit\XUnitFilterType.cs">
|
||||
<Link>TestRunner.xUnit\XUnitFilterType.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitResultFileFormat.cs">
|
||||
<Link>TestRunner.xUnit\XUnitResultFileFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="templates\common\TestRunner.xUnit\XUnitTestRunner.cs">
|
||||
<Link>TestRunner.xUnit\XUnitTestRunner.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// Modified version of the TouchOptions found in
|
||||
// Modified version of the TouchOptions found in
|
||||
using System;
|
||||
using Foundation;
|
||||
using Mono.Options;
|
||||
using Xamarin.iOS.UnitTests;
|
||||
|
||||
namespace BCLTests {
|
||||
|
||||
|
@ -10,6 +11,11 @@ namespace BCLTests {
|
|||
Wrapped = 1,
|
||||
}
|
||||
|
||||
public enum XmlVersion {
|
||||
NUnitV2 = 0,
|
||||
NUnitV3 = 1,
|
||||
}
|
||||
|
||||
public class ApplicationOptions {
|
||||
|
||||
static public ApplicationOptions Current = new ApplicationOptions ();
|
||||
|
@ -49,6 +55,9 @@ namespace BCLTests {
|
|||
var xml_mode = Environment.GetEnvironmentVariable ("NUNIT_ENABLE_XML_MODE");
|
||||
if (!string.IsNullOrEmpty (xml_mode))
|
||||
XmlMode = (XmlMode) Enum.Parse (typeof (XmlMode), xml_mode, true);
|
||||
var xml_version = Environment.GetEnvironmentVariable ("NUNIT_XML_VERSION");
|
||||
if (!string.IsNullOrEmpty (xml_version))
|
||||
XmlVersion = (XmlVersion)Enum.Parse (typeof (XmlVersion), xml_version, true);
|
||||
if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("NUNIT_LOG_FILE")))
|
||||
LogFile = Environment.GetEnvironmentVariable ("NUNIT_LOG_FILE");
|
||||
|
||||
|
@ -61,6 +70,7 @@ namespace BCLTests {
|
|||
{ "transport=", "Select transport method. Either TCP (default), HTTP or FILE.", v => Transport = v },
|
||||
{ "enablexml", "Enable the xml reported.", v => EnableXml = false },
|
||||
{ "xmlmode", "The xml mode.", v => XmlMode = (XmlMode) Enum.Parse (typeof (XmlMode), v, false) },
|
||||
{ "xmlversion", "The xml version.", v => XmlVersion = (XmlVersion) Enum.Parse (typeof (XmlVersion), v, false) },
|
||||
{ "logfile=", "A path where output will be saved.", v => LogFile = v },
|
||||
{ "result=", "The path to be used to store the result", v => ResultFile = v},
|
||||
};
|
||||
|
@ -76,6 +86,8 @@ namespace BCLTests {
|
|||
|
||||
public XmlMode XmlMode { get; set; }
|
||||
|
||||
public XmlVersion XmlVersion { get; set; } = XmlVersion.NUnitV2;
|
||||
|
||||
public bool EnableXml { get; set; }
|
||||
|
||||
public string HostName { get; private set; }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
@ -9,6 +9,13 @@ namespace Xamarin.iOS.UnitTests
|
|||
{
|
||||
public abstract class TestRunner
|
||||
{
|
||||
public enum Jargon {
|
||||
TouchUnit,
|
||||
NUnitV2,
|
||||
NUnitV3,
|
||||
xUnit,
|
||||
}
|
||||
|
||||
public long InconclusiveTests { get; protected set; } = 0;
|
||||
public long FailedTests { get; protected set; } = 0;
|
||||
public long PassedTests { get; protected set; } = 0;
|
||||
|
@ -32,8 +39,8 @@ namespace Xamarin.iOS.UnitTests
|
|||
}
|
||||
|
||||
public abstract Task Run (IEnumerable<TestAssemblyInfo> testAssemblies);
|
||||
public abstract string WriteResultsToFile ();
|
||||
public abstract void WriteResultsToFile (TextWriter writer);
|
||||
public abstract string WriteResultsToFile (Jargon jargon);
|
||||
public abstract void WriteResultsToFile (TextWriter writer, Jargon jargon);
|
||||
public abstract void SkipTests (IEnumerable<string> tests);
|
||||
public abstract void SkipCategories (IEnumerable<string> categories);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ using Foundation;
|
|||
using NUnit.Framework.Api;
|
||||
using NUnit.Framework.Internal;
|
||||
using NUnit.Framework.Internal.Filters;
|
||||
|
||||
using NUnitLite.Runner;
|
||||
using NUnitTest = NUnit.Framework.Internal.Test;
|
||||
|
||||
namespace Xamarin.iOS.UnitTests.NUnit
|
||||
|
@ -251,7 +251,7 @@ namespace Xamarin.iOS.UnitTests.NUnit
|
|||
}
|
||||
}
|
||||
|
||||
public override string WriteResultsToFile ()
|
||||
public override string WriteResultsToFile (Jargon jargon)
|
||||
{
|
||||
if (results == null)
|
||||
return string.Empty;
|
||||
|
@ -259,20 +259,40 @@ namespace Xamarin.iOS.UnitTests.NUnit
|
|||
string ret = GetResultsFilePath ();
|
||||
if (string.IsNullOrEmpty (ret))
|
||||
return string.Empty;
|
||||
|
||||
|
||||
var resultsXml = new NUnit2XmlOutputWriter (DateTime.UtcNow);
|
||||
resultsXml.WriteResultFile (results, ret);
|
||||
|
||||
OutputWriter formatter;
|
||||
switch (jargon) {
|
||||
case Jargon.NUnitV2:
|
||||
formatter = new NUnit2XmlOutputWriter (DateTime.UtcNow);
|
||||
break;
|
||||
case Jargon.NUnitV3:
|
||||
formatter = new NUnit3XmlOutputWriter (DateTime.UtcNow);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException ($"Jargon {jargon} is not supported by this runner.");
|
||||
}
|
||||
|
||||
formatter.WriteResultFile (results, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override void WriteResultsToFile (TextWriter writer)
|
||||
public override void WriteResultsToFile (TextWriter writer, Jargon jargon)
|
||||
{
|
||||
if (results == null)
|
||||
return;
|
||||
var resultsXml = new NUnit2XmlOutputWriter (DateTime.UtcNow);
|
||||
resultsXml.WriteResultFile (results, writer);
|
||||
OutputWriter formatter;
|
||||
switch (jargon) {
|
||||
case Jargon.NUnitV2:
|
||||
formatter = new NUnit2XmlOutputWriter (DateTime.UtcNow);
|
||||
break;
|
||||
case Jargon.NUnitV3:
|
||||
formatter = new NUnit3XmlOutputWriter (DateTime.UtcNow);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException ($"Jargon {jargon} is not supported by this runner.");
|
||||
}
|
||||
formatter.WriteResultFile (results, writer);
|
||||
}
|
||||
|
||||
void AppendFilter (ITestFilter filter)
|
||||
|
|
|
@ -1,349 +0,0 @@
|
|||
// ***********************************************************************
|
||||
// Copyright (c) 2011 Charlie Poole
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using NUnit.Framework.Api;
|
||||
using NUnit.Framework.Internal;
|
||||
using NUnitLite.Runner;
|
||||
#if CLR_2_0 || CLR_4_0
|
||||
using System.Collections.Generic;
|
||||
#else
|
||||
using System.Collections.Specialized;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.iOS.UnitTests.NUnit {
|
||||
/// <summary>
|
||||
/// NUnit2XmlOutputWriter is able to create an xml file representing
|
||||
/// the result of a test run in NUnit 2.x format.
|
||||
/// </summary>
|
||||
public class NUnit2XmlOutputWriter : OutputWriter {
|
||||
private XmlWriter xmlWriter;
|
||||
private DateTime startTime;
|
||||
|
||||
#if CLR_2_0 || CLR_4_0
|
||||
private static Dictionary<string, string> resultStates = new Dictionary<string, string>();
|
||||
#else
|
||||
private static StringDictionary resultStates = new StringDictionary ();
|
||||
#endif
|
||||
|
||||
static NUnit2XmlOutputWriter ()
|
||||
{
|
||||
resultStates ["Passed"] = "Success";
|
||||
resultStates ["Failed"] = "Failure";
|
||||
resultStates ["Failed:Error"] = "Error";
|
||||
resultStates ["Failed:Cancelled"] = "Cancelled";
|
||||
resultStates ["Inconclusive"] = "Inconclusive";
|
||||
resultStates ["Skipped"] = "Skipped";
|
||||
resultStates ["Skipped:Ignored"] = "Ignored";
|
||||
resultStates ["Skipped:Invalid"] = "NotRunnable";
|
||||
}
|
||||
|
||||
public NUnit2XmlOutputWriter (DateTime startTime)
|
||||
{
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public override void WriteResultFile (ITestResult result, TextWriter writer)
|
||||
{
|
||||
// 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))
|
||||
#if SILVERLIGHT
|
||||
XmlWriter xmlWriter = XmlWriter.Create(writer);
|
||||
#else
|
||||
XmlTextWriter xmlWriter = new XmlTextWriter (writer);
|
||||
xmlWriter.Formatting = Formatting.Indented;
|
||||
#endif
|
||||
|
||||
try {
|
||||
WriteXmlOutput (result, xmlWriter);
|
||||
} finally {
|
||||
writer.Close ();
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteXmlOutput (ITestResult result, XmlWriter xmlWriter)
|
||||
{
|
||||
this.xmlWriter = xmlWriter;
|
||||
|
||||
InitializeXmlFile (result);
|
||||
WriteResultElement (result);
|
||||
TerminateXmlFile ();
|
||||
}
|
||||
|
||||
private void InitializeXmlFile (ITestResult result)
|
||||
{
|
||||
ResultSummary summaryResults = new ResultSummary (result);
|
||||
|
||||
xmlWriter.WriteStartDocument (false);
|
||||
xmlWriter.WriteComment ("This file represents the results of running a test suite");
|
||||
|
||||
xmlWriter.WriteStartElement ("test-results");
|
||||
|
||||
xmlWriter.WriteAttributeString ("name", result.FullName);
|
||||
xmlWriter.WriteAttributeString ("total", summaryResults.TestCount.ToString ());
|
||||
xmlWriter.WriteAttributeString ("errors", summaryResults.ErrorCount.ToString ());
|
||||
xmlWriter.WriteAttributeString ("failures", summaryResults.FailureCount.ToString ());
|
||||
xmlWriter.WriteAttributeString ("not-run", summaryResults.NotRunCount.ToString ());
|
||||
xmlWriter.WriteAttributeString ("inconclusive", summaryResults.InconclusiveCount.ToString ());
|
||||
xmlWriter.WriteAttributeString ("ignored", summaryResults.IgnoreCount.ToString ());
|
||||
xmlWriter.WriteAttributeString ("skipped", summaryResults.SkipCount.ToString ());
|
||||
xmlWriter.WriteAttributeString ("invalid", summaryResults.InvalidCount.ToString ());
|
||||
|
||||
xmlWriter.WriteAttributeString ("date", XmlConvert.ToString (startTime, "yyyy-MM-dd"));
|
||||
xmlWriter.WriteAttributeString ("time", XmlConvert.ToString (startTime, "HH:mm:ss"));
|
||||
WriteEnvironment ();
|
||||
WriteCultureInfo ();
|
||||
xmlWriter.Flush ();
|
||||
}
|
||||
|
||||
private void WriteCultureInfo ()
|
||||
{
|
||||
xmlWriter.WriteStartElement ("culture-info");
|
||||
xmlWriter.WriteAttributeString ("current-culture",
|
||||
CultureInfo.CurrentCulture.ToString ());
|
||||
xmlWriter.WriteAttributeString ("current-uiculture",
|
||||
CultureInfo.CurrentUICulture.ToString ());
|
||||
xmlWriter.WriteEndElement ();
|
||||
xmlWriter.Flush ();
|
||||
}
|
||||
|
||||
private void WriteEnvironment ()
|
||||
{
|
||||
xmlWriter.WriteStartElement ("environment");
|
||||
AssemblyName assemblyName = AssemblyHelper.GetAssemblyName (Assembly.GetExecutingAssembly ());
|
||||
xmlWriter.WriteAttributeString ("nunit-version",
|
||||
assemblyName.Version.ToString ());
|
||||
xmlWriter.WriteAttributeString ("clr-version",
|
||||
Environment.Version.ToString ());
|
||||
xmlWriter.WriteAttributeString ("os-version",
|
||||
Environment.OSVersion.ToString ());
|
||||
xmlWriter.WriteAttributeString ("platform",
|
||||
Environment.OSVersion.Platform.ToString ());
|
||||
#if !NETCF
|
||||
xmlWriter.WriteAttributeString ("cwd",
|
||||
Environment.CurrentDirectory);
|
||||
#if !SILVERLIGHT
|
||||
xmlWriter.WriteAttributeString ("machine-name",
|
||||
Environment.MachineName);
|
||||
xmlWriter.WriteAttributeString ("user",
|
||||
Environment.UserName);
|
||||
xmlWriter.WriteAttributeString ("user-domain",
|
||||
Environment.UserDomainName);
|
||||
#endif
|
||||
#endif
|
||||
xmlWriter.WriteEndElement ();
|
||||
xmlWriter.Flush ();
|
||||
}
|
||||
|
||||
private void WriteResultElement (ITestResult result)
|
||||
{
|
||||
StartTestElement (result);
|
||||
|
||||
WriteProperties (result);
|
||||
|
||||
switch (result.ResultState.Status) {
|
||||
case TestStatus.Skipped:
|
||||
WriteReasonElement (result.Message);
|
||||
break;
|
||||
case TestStatus.Failed:
|
||||
WriteFailureElement (result.Message, result.StackTrace);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.Test is TestSuite)
|
||||
WriteChildResults (result);
|
||||
|
||||
xmlWriter.WriteEndElement (); // test element
|
||||
xmlWriter.Flush ();
|
||||
}
|
||||
|
||||
private void TerminateXmlFile ()
|
||||
{
|
||||
xmlWriter.WriteEndElement (); // test-results
|
||||
xmlWriter.WriteEndDocument ();
|
||||
xmlWriter.Flush ();
|
||||
xmlWriter.Close ();
|
||||
}
|
||||
|
||||
|
||||
#region Element Creation Helpers
|
||||
|
||||
private void StartTestElement (ITestResult result)
|
||||
{
|
||||
ITest test = result.Test;
|
||||
TestSuite suite = test as TestSuite;
|
||||
|
||||
if (suite != null) {
|
||||
xmlWriter.WriteStartElement ("test-suite");
|
||||
xmlWriter.WriteAttributeString ("type", suite.TestType);
|
||||
xmlWriter.WriteAttributeString ("name", suite.TestType == "Assembly"
|
||||
? result.Test.FullName
|
||||
: result.Test.Name);
|
||||
} else {
|
||||
xmlWriter.WriteStartElement ("test-case");
|
||||
xmlWriter.WriteAttributeString ("name", result.Name);
|
||||
}
|
||||
|
||||
if (test.Properties.ContainsKey (PropertyNames.Description)) {
|
||||
string description = (string)test.Properties.Get (PropertyNames.Description);
|
||||
xmlWriter.WriteAttributeString ("description", description);
|
||||
}
|
||||
|
||||
TestStatus status = result.ResultState.Status;
|
||||
string translatedResult = resultStates [result.ResultState.ToString ()];
|
||||
|
||||
if (status != TestStatus.Skipped) {
|
||||
xmlWriter.WriteAttributeString ("executed", "True");
|
||||
xmlWriter.WriteAttributeString ("result", translatedResult);
|
||||
xmlWriter.WriteAttributeString ("success", status == TestStatus.Passed ? "True" : "False");
|
||||
xmlWriter.WriteAttributeString ("time", result.Duration.TotalSeconds.ToString ());
|
||||
xmlWriter.WriteAttributeString ("asserts", result.AssertCount.ToString ());
|
||||
} else {
|
||||
xmlWriter.WriteAttributeString ("executed", "False");
|
||||
xmlWriter.WriteAttributeString ("result", translatedResult);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteProperties (ITestResult result)
|
||||
{
|
||||
IPropertyBag properties = result.Test.Properties;
|
||||
int nprops = 0;
|
||||
|
||||
foreach (string key in properties.Keys) {
|
||||
if (key != PropertyNames.Category) {
|
||||
if (nprops++ == 0)
|
||||
xmlWriter.WriteStartElement ("properties");
|
||||
|
||||
foreach (object prop in properties [key]) {
|
||||
xmlWriter.WriteStartElement ("property");
|
||||
xmlWriter.WriteAttributeString ("name", key);
|
||||
xmlWriter.WriteAttributeString ("value", prop.ToString ());
|
||||
xmlWriter.WriteEndElement ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nprops > 0)
|
||||
xmlWriter.WriteEndElement ();
|
||||
}
|
||||
|
||||
private void WriteReasonElement (string message)
|
||||
{
|
||||
xmlWriter.WriteStartElement ("reason");
|
||||
xmlWriter.WriteStartElement ("message");
|
||||
xmlWriter.WriteCData (message);
|
||||
xmlWriter.WriteEndElement ();
|
||||
xmlWriter.WriteEndElement ();
|
||||
}
|
||||
|
||||
private void WriteFailureElement (string message, string stackTrace)
|
||||
{
|
||||
xmlWriter.WriteStartElement ("failure");
|
||||
xmlWriter.WriteStartElement ("message");
|
||||
WriteCData (message);
|
||||
xmlWriter.WriteEndElement ();
|
||||
xmlWriter.WriteStartElement ("stack-trace");
|
||||
if (stackTrace != null)
|
||||
WriteCData (stackTrace);
|
||||
xmlWriter.WriteEndElement ();
|
||||
xmlWriter.WriteEndElement ();
|
||||
}
|
||||
|
||||
private void WriteChildResults (ITestResult result)
|
||||
{
|
||||
xmlWriter.WriteStartElement ("results");
|
||||
|
||||
foreach (ITestResult childResult in result.Children)
|
||||
WriteResultElement (childResult);
|
||||
|
||||
xmlWriter.WriteEndElement ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Output Helpers
|
||||
///// <summary>
|
||||
///// Makes string safe for xml parsing, replacing control chars with '?'
|
||||
///// </summary>
|
||||
///// <param name="encodedString">string to make safe</param>
|
||||
///// <returns>xml safe string</returnCs>
|
||||
//private static string CharacterSafeString(string encodedString)
|
||||
//{
|
||||
// /*The default code page for the system will be used.
|
||||
// Since all code pages use the same lower 128 bytes, this should be sufficient
|
||||
// for finding uprintable control characters that make the xslt processor error.
|
||||
// We use characters encoded by the default code page to avoid mistaking bytes as
|
||||
// individual characters on non-latin code pages.*/
|
||||
// char[] encodedChars = System.Text.Encoding.Default.GetChars(System.Text.Encoding.Default.GetBytes(encodedString));
|
||||
|
||||
// System.Collections.ArrayList pos = new System.Collections.ArrayList();
|
||||
// for (int x = 0; x < encodedChars.Length; x++)
|
||||
// {
|
||||
// char currentChar = encodedChars[x];
|
||||
// //unprintable characters are below 0x20 in Unicode tables
|
||||
// //some control characters are acceptable. (carriage return 0x0D, line feed 0x0A, horizontal tab 0x09)
|
||||
// if (currentChar < 32 && (currentChar != 9 && currentChar != 10 && currentChar != 13))
|
||||
// {
|
||||
// //save the array index for later replacement.
|
||||
// pos.Add(x);
|
||||
// }
|
||||
// }
|
||||
// foreach (int index in pos)
|
||||
// {
|
||||
// encodedChars[index] = '?';//replace unprintable control characters with ?(3F)
|
||||
// }
|
||||
// return System.Text.Encoding.Default.GetString(System.Text.Encoding.Default.GetBytes(encodedChars));
|
||||
//}
|
||||
|
||||
private void WriteCData (string text)
|
||||
{
|
||||
int start = 0;
|
||||
while (true) {
|
||||
int illegal = text.IndexOf ("]]>", start);
|
||||
if (illegal < 0)
|
||||
break;
|
||||
xmlWriter.WriteCData (text.Substring (start, illegal - start + 2));
|
||||
start = illegal + 2;
|
||||
if (start >= text.Length)
|
||||
return;
|
||||
}
|
||||
|
||||
if (start > 0)
|
||||
xmlWriter.WriteCData (text.Substring (start));
|
||||
else
|
||||
xmlWriter.WriteCData (text);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
namespace Xamarin.iOS.UnitTests.XUnit
|
||||
{
|
||||
public enum XUnitResultFileFormat
|
||||
{
|
||||
XunitV2,
|
||||
XunitV1,
|
||||
NUnit
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@ namespace Xamarin.iOS.UnitTests.XUnit
|
|||
List<XUnitFilter> filters = new List<XUnitFilter> ();
|
||||
bool runAssemblyByDefault;
|
||||
|
||||
public XUnitResultFileFormat ResultFileFormat { get; set; } = XUnitResultFileFormat.XunitV2;
|
||||
public AppDomainSupport AppDomainSupport { get; set; } = AppDomainSupport.Denied;
|
||||
protected override string ResultsFileName { get; set; } = "TestResults.xUnit.xml";
|
||||
|
||||
|
@ -791,7 +790,7 @@ namespace Xamarin.iOS.UnitTests.XUnit
|
|||
}
|
||||
}
|
||||
|
||||
public override string WriteResultsToFile ()
|
||||
public override string WriteResultsToFile (Jargon jargon)
|
||||
{
|
||||
if (assembliesElement == null)
|
||||
return String.Empty;
|
||||
|
@ -800,22 +799,20 @@ namespace Xamarin.iOS.UnitTests.XUnit
|
|||
string outputFilePath = GetResultsFilePath ();
|
||||
var settings = new XmlWriterSettings { Indent = true};
|
||||
using (var xmlWriter = XmlWriter.Create (outputFilePath, settings)) {
|
||||
switch (ResultFileFormat) {
|
||||
case XUnitResultFileFormat.XunitV2:
|
||||
assembliesElement.Save (xmlWriter);
|
||||
break;
|
||||
case XUnitResultFileFormat.NUnit:
|
||||
switch (jargon) {
|
||||
case Jargon.NUnitV2:
|
||||
Transform_Results ("NUnitXml.xslt", assembliesElement, xmlWriter); // TODO: Add resource
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException ($"Result output format '{ResultFileFormat}' is not currently supported");
|
||||
default: // default to xunit until we implement NUnit v3 support.
|
||||
assembliesElement.Save (xmlWriter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return outputFilePath;
|
||||
}
|
||||
public override void WriteResultsToFile (TextWriter writer)
|
||||
public override void WriteResultsToFile (TextWriter writer, Jargon jargon)
|
||||
{
|
||||
if (assembliesElement == null)
|
||||
return;
|
||||
|
@ -823,11 +820,8 @@ namespace Xamarin.iOS.UnitTests.XUnit
|
|||
assembliesElement.Descendants ().Where (e => e.Name == "collection" && !e.Descendants ().Any ()).Remove ();
|
||||
var settings = new XmlWriterSettings { Indent = true };
|
||||
using (var xmlWriter = XmlWriter.Create (writer, settings)) {
|
||||
switch (ResultFileFormat) {
|
||||
case XUnitResultFileFormat.XunitV2:
|
||||
assembliesElement.Save (xmlWriter);
|
||||
break;
|
||||
case XUnitResultFileFormat.NUnit:
|
||||
switch (jargon) {
|
||||
case Jargon.NUnitV2:
|
||||
try {
|
||||
Transform_Results ("NUnitXml.xslt", assembliesElement, xmlWriter);
|
||||
} catch (Exception e) {
|
||||
|
@ -835,8 +829,9 @@ namespace Xamarin.iOS.UnitTests.XUnit
|
|||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException ($"Result output format '{ResultFileFormat}' is not currently supported");
|
||||
default: // defualt to xunit until we add NUnitv3 support
|
||||
assembliesElement.Save (xmlWriter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UIKit;
|
||||
|
@ -9,11 +8,8 @@ using Xamarin.iOS.UnitTests;
|
|||
using Xamarin.iOS.UnitTests.NUnit;
|
||||
using BCLTests.TestRunner.Core;
|
||||
using Xamarin.iOS.UnitTests.XUnit;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Foundation;
|
||||
using NUnit.Framework.Internal.Filters;
|
||||
|
||||
namespace BCLTests {
|
||||
public partial class ViewController : UIViewController {
|
||||
|
@ -95,11 +91,21 @@ namespace BCLTests {
|
|||
}
|
||||
await runner.Run (testAssemblies).ConfigureAwait (false);
|
||||
|
||||
Xamarin.iOS.UnitTests.TestRunner.Jargon jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV3;
|
||||
switch (options.XmlVersion) {
|
||||
default:
|
||||
case XmlVersion.NUnitV2:
|
||||
jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV2;
|
||||
break;
|
||||
case XmlVersion.NUnitV3:
|
||||
jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV3;
|
||||
break;
|
||||
}
|
||||
if (options.EnableXml) {
|
||||
runner.WriteResultsToFile (writer);
|
||||
runner.WriteResultsToFile (writer, jargon);
|
||||
logger.Info ("Xml file was written to the tcp listener.");
|
||||
} else {
|
||||
string resultsFilePath = runner.WriteResultsToFile ();
|
||||
string resultsFilePath = runner.WriteResultsToFile (jargon);
|
||||
logger.Info ($"Xml result can be found {resultsFilePath}");
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace Xamarin.Mac.Tests
|
|||
|
||||
if (options.ResultFile != null) {
|
||||
using (var writer = new StreamWriter (options.ResultFile)) {
|
||||
runner.WriteResultsToFile (writer);
|
||||
runner.WriteResultsToFile (writer, TestRunner.Jargon.NUnitV3);
|
||||
}
|
||||
logger.Info ($"Xml result can be found {options.ResultFile}");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
@ -86,11 +86,21 @@ namespace BCLTests {
|
|||
}
|
||||
|
||||
await runner.Run (testAssemblies).ConfigureAwait (false);
|
||||
Xamarin.iOS.UnitTests.TestRunner.Jargon jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV3;
|
||||
switch (options.XmlVersion) {
|
||||
default:
|
||||
case XmlVersion.NUnitV2:
|
||||
jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV2;
|
||||
break;
|
||||
case XmlVersion.NUnitV3:
|
||||
jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV3;
|
||||
break;
|
||||
}
|
||||
if (options.EnableXml) {
|
||||
runner.WriteResultsToFile (writer);
|
||||
runner.WriteResultsToFile (writer, jargon);
|
||||
logger.Info ("Xml file was written to the tcp listener.");
|
||||
} else {
|
||||
string resultsFilePath = runner.WriteResultsToFile ();
|
||||
string resultsFilePath = runner.WriteResultsToFile (jargon);
|
||||
logger.Info ($"Xml result can be found {resultsFilePath}");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
@ -131,11 +131,21 @@ namespace monotouchtestWatchKitExtension
|
|||
RenderResults ();
|
||||
cmdRun.SetEnabled (true);
|
||||
cmdRun.SetHidden (false);
|
||||
Xamarin.iOS.UnitTests.TestRunner.Jargon jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV3;
|
||||
switch (options.XmlVersion) {
|
||||
default:
|
||||
case XmlVersion.NUnitV2:
|
||||
jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV2;
|
||||
break;
|
||||
case XmlVersion.NUnitV3:
|
||||
jargon = Xamarin.iOS.UnitTests.TestRunner.Jargon.NUnitV3;
|
||||
break;
|
||||
}
|
||||
if (options.EnableXml) {
|
||||
runner.WriteResultsToFile (writer);
|
||||
runner.WriteResultsToFile (writer, jargon);
|
||||
logger.Info ("Xml file was written to the http listener.");
|
||||
} else {
|
||||
string resultsFilePath = runner.WriteResultsToFile ();
|
||||
string resultsFilePath = runner.WriteResultsToFile (jargon);
|
||||
logger.Info ($"Xml result can be found {resultsFilePath}");
|
||||
}
|
||||
logger.Info ($"Tests run: {runner.TotalTests} Passed: {runner.PassedTests} Inconclusive: {runner.InconclusiveTests} Failed: {runner.FailedTests} Ignored: {runner.FilteredTests}");
|
||||
|
|
Загрузка…
Ссылка в новой задаче