Add multiple assembly running
This commit is contained in:
Родитель
677973e071
Коммит
ab94ca7e82
|
@ -54,6 +54,7 @@
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
<HintPath>..\..\..\packages\Xamarin.Forms.2.3.3.168\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ImportGroup>
|
<ImportGroup>
|
||||||
<Import Project="$(NuGetPackageRoot)\Xamarin.Forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)\Xamarin.Forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
<Import Project="$(NuGetPackageRoot)xamarin.forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)xamarin.forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -1,4 +1,27 @@
|
||||||
using NUnit.Framework.Interfaces;
|
// ***********************************************************************
|
||||||
|
// Copyright (c) 2017 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 NUnit.Framework.Interfaces;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace NUnit.Runner.Extensions
|
namespace NUnit.Runner.Extensions
|
||||||
|
@ -10,18 +33,18 @@ namespace NUnit.Runner.Extensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="result"></param>
|
/// <param name="result"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Color Color(this ITestResult result)
|
public static Color Color(this ResultState result)
|
||||||
{
|
{
|
||||||
switch (result.ResultState.Status)
|
switch (result.Status)
|
||||||
{
|
{
|
||||||
case TestStatus.Passed:
|
case TestStatus.Passed:
|
||||||
return Xamarin.Forms.Color.Green;
|
return Xamarin.Forms.Color.Green;
|
||||||
case TestStatus.Skipped:
|
case TestStatus.Skipped:
|
||||||
return Xamarin.Forms.Color.FromRgb(206, 172, 0); // Dark Yellow
|
return Xamarin.Forms.Color.FromRgb(206, 172, 0); // Dark Yellow
|
||||||
case TestStatus.Failed:
|
case TestStatus.Failed:
|
||||||
if (result.ResultState == ResultState.Failure)
|
if (result == ResultState.Failure)
|
||||||
return Xamarin.Forms.Color.Red;
|
return Xamarin.Forms.Color.Red;
|
||||||
if (result.ResultState == ResultState.NotRunnable)
|
if (result == ResultState.NotRunnable)
|
||||||
return Xamarin.Forms.Color.FromRgb(255, 106, 0); // Orange
|
return Xamarin.Forms.Color.FromRgb(255, 106, 0); // Orange
|
||||||
|
|
||||||
return Xamarin.Forms.Color.FromRgb(170, 0, 0); // Dark Red
|
return Xamarin.Forms.Color.FromRgb(170, 0, 0); // Dark Red
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
// Copyright (c) 2014 Charlie Poole
|
// Copyright (c) 2017 Charlie Poole
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
|
@ -21,32 +21,80 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Xml.Linq;
|
||||||
using NUnit.Framework.Interfaces;
|
using NUnit.Framework.Interfaces;
|
||||||
using NUnit.Runner.Extensions;
|
using NUnit.Runner.Extensions;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Nunit.Runner.ViewModel
|
namespace NUnit.Runner.Helpers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper class used to summarize the result of a test run
|
/// Helper class used to summarize the result of a test run.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ResultSummary
|
internal class ResultSummary
|
||||||
{
|
{
|
||||||
|
private readonly TestRunResult _results;
|
||||||
|
private XDocument _xmlResults;
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
|
|
||||||
/// <summary>
|
public ResultSummary(TestRunResult results)
|
||||||
/// Initializes a new instance of the <see cref="ResultSummary"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="result">The result.</param>
|
|
||||||
public ResultSummary(ITestResult result)
|
|
||||||
{
|
{
|
||||||
TestResult = result;
|
_results = results;
|
||||||
InitializeCounters();
|
Initialize();
|
||||||
Summarize(result);
|
Summarize(results.TestResults);
|
||||||
|
}
|
||||||
|
|
||||||
OverallResult = result.ResultState.Status.ToString();
|
#endregion
|
||||||
if (OverallResult == "Skipped")
|
|
||||||
OverallResult = "Warning";
|
#region Public Methods
|
||||||
|
/// <summary>
|
||||||
|
///Gets all TestResults
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IReadOnlyCollection<ITestResult> GetTestResults()
|
||||||
|
{
|
||||||
|
return _results.TestResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Summarizes all of the results and returns the test result xml document
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public XDocument GetTestXml()
|
||||||
|
{
|
||||||
|
if (_xmlResults != null)
|
||||||
|
return _xmlResults;
|
||||||
|
|
||||||
|
var test = new XElement("test-run");
|
||||||
|
test.Add(new XAttribute("id", "0"));
|
||||||
|
test.Add(new XAttribute("testcasecount", TestCount));
|
||||||
|
test.Add(new XAttribute("total", TestCount));
|
||||||
|
test.Add(new XAttribute("passed", PassCount));
|
||||||
|
test.Add(new XAttribute("failed", FailureCount));
|
||||||
|
test.Add(new XAttribute("inconclusive", InconclusiveCount));
|
||||||
|
test.Add(new XAttribute("skipped", SkipCount));
|
||||||
|
test.Add(new XAttribute("asserts", AssertCount));
|
||||||
|
test.Add(new XAttribute("result", OverallResult));
|
||||||
|
|
||||||
|
test.Add(new XAttribute("xamarin-runner-version", typeof(ResultSummary).GetTypeInfo().Assembly.GetName().Version.ToString()));
|
||||||
|
|
||||||
|
var startTime = _results.StartTime;
|
||||||
|
var endTime = _results.EndTime;
|
||||||
|
var duration = endTime.Subtract(startTime).TotalSeconds;
|
||||||
|
|
||||||
|
test.Add(new XAttribute("start-time", startTime.ToString("u")));
|
||||||
|
test.Add(new XAttribute("end-time", endTime.ToString("u")));
|
||||||
|
test.Add(new XAttribute("duration", duration.ToString("0.000000", NumberFormatInfo.InvariantInfo)));
|
||||||
|
|
||||||
|
foreach (var result in _results.TestResults)
|
||||||
|
test.Add(XElement.Parse(result.ToXml(true).OuterXml));
|
||||||
|
|
||||||
|
_xmlResults = new XDocument(test);
|
||||||
|
return _xmlResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -54,21 +102,16 @@ namespace Nunit.Runner.ViewModel
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the test result this summary was created with
|
/// The overall result of the test run.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ITestResult TestResult { get; private set; }
|
public TestStatus OverallResult { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A string representation of the overall result of the test run.
|
|
||||||
/// </summary>
|
|
||||||
public string OverallResult { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the color for the overall result.
|
/// Gets the color for the overall result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color OverallResultColor
|
public Color OverallResultColor
|
||||||
{
|
{
|
||||||
get { return TestResult.Color(); }
|
get { return new ResultState(OverallResult).Color(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -78,17 +121,22 @@ namespace Nunit.Runner.ViewModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int TestCount { get; private set; }
|
public int TestCount { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of asserts
|
||||||
|
/// </summary>
|
||||||
|
public int AssertCount { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the number of test cases actually run.
|
/// Returns the number of test cases actually run.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int RunCount { get { return PassCount + FailureCount + ErrorCount + InconclusiveCount; } }
|
public int RunCount { get { return PassCount + FailureCount + ErrorCount + InconclusiveCount; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the number of test cases not run for any reason.
|
/// Returns the number of test cases not run for any reason.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int NotRunCount
|
public int NotRunCount
|
||||||
{
|
{
|
||||||
get { return IgnoreCount + ExplicitCount + InvalidCount + SkipCount; }
|
get { return IgnoreCount + ExplicitCount + InvalidCount + SkipCount; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -137,7 +185,7 @@ namespace Nunit.Runner.ViewModel
|
||||||
|
|
||||||
#region Helper Methods
|
#region Helper Methods
|
||||||
|
|
||||||
private void InitializeCounters()
|
private void Initialize()
|
||||||
{
|
{
|
||||||
TestCount = 0;
|
TestCount = 0;
|
||||||
PassCount = 0;
|
PassCount = 0;
|
||||||
|
@ -148,10 +196,19 @@ namespace Nunit.Runner.ViewModel
|
||||||
IgnoreCount = 0;
|
IgnoreCount = 0;
|
||||||
ExplicitCount = 0;
|
ExplicitCount = 0;
|
||||||
InvalidCount = 0;
|
InvalidCount = 0;
|
||||||
|
OverallResult = TestStatus.Inconclusive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Summarize(IEnumerable<ITestResult> results)
|
||||||
|
{
|
||||||
|
foreach (var result in results)
|
||||||
|
Summarize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Summarize(ITestResult result)
|
private void Summarize(ITestResult result)
|
||||||
{
|
{
|
||||||
|
var status = TestStatus.Inconclusive;
|
||||||
|
|
||||||
if (result.Test.IsSuite)
|
if (result.Test.IsSuite)
|
||||||
{
|
{
|
||||||
foreach (ITestResult r in result.Children)
|
foreach (ITestResult r in result.Children)
|
||||||
|
@ -160,34 +217,52 @@ namespace Nunit.Runner.ViewModel
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TestCount++;
|
TestCount++;
|
||||||
|
AssertCount += result.AssertCount;
|
||||||
switch (result.ResultState.Status)
|
switch (result.ResultState.Status)
|
||||||
{
|
{
|
||||||
case TestStatus.Passed:
|
case TestStatus.Passed:
|
||||||
PassCount++;
|
PassCount++;
|
||||||
|
if (status == TestStatus.Inconclusive)
|
||||||
|
status = TestStatus.Passed;
|
||||||
|
break;
|
||||||
|
case TestStatus.Failed:
|
||||||
|
status = TestStatus.Failed;
|
||||||
|
if (result.ResultState == ResultState.Failure)
|
||||||
|
FailureCount++;
|
||||||
|
else if (result.ResultState == ResultState.NotRunnable)
|
||||||
|
InvalidCount++;
|
||||||
|
else
|
||||||
|
ErrorCount++;
|
||||||
|
break;
|
||||||
|
case TestStatus.Skipped:
|
||||||
|
if (result.ResultState == ResultState.Ignored)
|
||||||
|
IgnoreCount++;
|
||||||
|
else if (result.ResultState == ResultState.Explicit)
|
||||||
|
ExplicitCount++;
|
||||||
|
else
|
||||||
|
SkipCount++;
|
||||||
|
break;
|
||||||
|
case TestStatus.Inconclusive:
|
||||||
|
InconclusiveCount++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (OverallResult)
|
||||||
|
{
|
||||||
|
case TestStatus.Inconclusive:
|
||||||
|
OverallResult = status;
|
||||||
break;
|
break;
|
||||||
case TestStatus.Failed:
|
case TestStatus.Passed:
|
||||||
if (result.ResultState == ResultState.Failure)
|
if (status == TestStatus.Failed)
|
||||||
FailureCount++;
|
OverallResult = status;
|
||||||
else if (result.ResultState == ResultState.NotRunnable)
|
|
||||||
InvalidCount++;
|
|
||||||
else
|
|
||||||
ErrorCount++;
|
|
||||||
break;
|
break;
|
||||||
case TestStatus.Skipped:
|
case TestStatus.Skipped:
|
||||||
if (result.ResultState == ResultState.Ignored)
|
case TestStatus.Failed:
|
||||||
IgnoreCount++;
|
default:
|
||||||
else if (result.ResultState == ResultState.Explicit)
|
|
||||||
ExplicitCount++;
|
|
||||||
else
|
|
||||||
SkipCount++;
|
|
||||||
break;
|
|
||||||
case TestStatus.Inconclusive:
|
|
||||||
InconclusiveCount++;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
// ***********************************************************************
|
||||||
|
// Copyright (c) 2017 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.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NUnit.Framework.Api;
|
||||||
|
using NUnit.Framework.Interfaces;
|
||||||
|
using NUnit.Framework.Internal;
|
||||||
|
|
||||||
|
namespace NUnit.Runner.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains all assemblies for a test run, and controls execution of tests and collection of results
|
||||||
|
/// </summary>
|
||||||
|
internal class TestPackage
|
||||||
|
{
|
||||||
|
private readonly List<Assembly> _testAssemblies = new List<Assembly>();
|
||||||
|
|
||||||
|
public void AddAssembly(Assembly testAssembly)
|
||||||
|
{
|
||||||
|
_testAssemblies.Add(testAssembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<TestRunResult> ExecuteTests()
|
||||||
|
{
|
||||||
|
var resultPackage = new TestRunResult();
|
||||||
|
|
||||||
|
foreach (var assembly in _testAssemblies)
|
||||||
|
{
|
||||||
|
NUnitTestAssemblyRunner runner = await LoadTestAssemblyAsync(assembly).ConfigureAwait(false);
|
||||||
|
ITestResult result = await Task.Run(() => runner.Run(TestListener.NULL, TestFilter.Empty)).ConfigureAwait(false);
|
||||||
|
resultPackage.AddResult(result);
|
||||||
|
}
|
||||||
|
resultPackage.CompleteTestRun();
|
||||||
|
return resultPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<NUnitTestAssemblyRunner> LoadTestAssemblyAsync(Assembly assembly)
|
||||||
|
{
|
||||||
|
var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
|
||||||
|
await Task.Run(() => runner.Load(assembly, new Dictionary<string, object>()));
|
||||||
|
return runner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
// ***********************************************************************
|
||||||
|
// Copyright (c) 2017 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.Collections.Generic;
|
||||||
|
using NUnit.Framework.Interfaces;
|
||||||
|
|
||||||
|
namespace NUnit.Runner.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains all results from all tests in a <see cref="TestPackage"/>
|
||||||
|
/// </summary>
|
||||||
|
internal class TestRunResult
|
||||||
|
{
|
||||||
|
private readonly List<ITestResult> _results = new List<ITestResult>();
|
||||||
|
|
||||||
|
public DateTime StartTime { get; private set; }
|
||||||
|
public DateTime EndTime { get; private set; }
|
||||||
|
|
||||||
|
public TestRunResult()
|
||||||
|
{
|
||||||
|
StartTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddResult(ITestResult result)
|
||||||
|
{
|
||||||
|
_results.Add(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CompleteTestRun()
|
||||||
|
{
|
||||||
|
EndTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IReadOnlyCollection<ITestResult> TestResults => _results;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,25 @@
|
||||||
|
// ***********************************************************************
|
||||||
|
// Copyright (c) 2017 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.
|
||||||
|
// ***********************************************************************
|
||||||
|
|
||||||
namespace NUnit.Runner.Messages
|
namespace NUnit.Runner.Messages
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@ using System.Threading.Tasks;
|
||||||
using NUnit.Framework.Interfaces;
|
using NUnit.Framework.Interfaces;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using NUnit.Runner.Messages;
|
using NUnit.Runner.Messages;
|
||||||
|
using NUnit.Runner.Helpers;
|
||||||
|
|
||||||
namespace NUnit.Runner.Services
|
namespace NUnit.Runner.Services
|
||||||
{
|
{
|
||||||
|
@ -37,13 +38,13 @@ namespace NUnit.Runner.Services
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Process(ITestResult testResult)
|
public override async Task Process(ResultSummary result)
|
||||||
{
|
{
|
||||||
if (Options.TcpWriterParameters != null)
|
if (Options.TcpWriterParameters != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await WriteResult(testResult);
|
await WriteResult(result);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -54,16 +55,16 @@ namespace NUnit.Runner.Services
|
||||||
|
|
||||||
if (Successor != null)
|
if (Successor != null)
|
||||||
{
|
{
|
||||||
await Successor.Process(testResult);
|
await Successor.Process(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task WriteResult(ITestResult testResult)
|
private async Task WriteResult(ResultSummary testResult)
|
||||||
{
|
{
|
||||||
using (var tcpWriter = new TcpWriter(Options.TcpWriterParameters))
|
using (var tcpWriter = new TcpWriter(Options.TcpWriterParameters))
|
||||||
{
|
{
|
||||||
await tcpWriter.Connect().ConfigureAwait(false);
|
await tcpWriter.Connect().ConfigureAwait(false);
|
||||||
tcpWriter.Write(testResult.ToXml(true).OuterXml);
|
tcpWriter.Write(testResult.GetTestXml());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using NUnit.Runner.Helpers;
|
||||||
using NUnit.Framework.Interfaces;
|
|
||||||
|
|
||||||
namespace NUnit.Runner.Services
|
namespace NUnit.Runner.Services
|
||||||
{
|
{
|
||||||
|
@ -36,9 +35,9 @@ namespace NUnit.Runner.Services
|
||||||
|
|
||||||
protected TestOptions Options { get; private set; }
|
protected TestOptions Options { get; private set; }
|
||||||
|
|
||||||
public TestResultProcessor Successor { get; set; }
|
protected TestResultProcessor Successor { get; private set; }
|
||||||
|
|
||||||
public abstract Task Process(ITestResult testResult);
|
public abstract Task Process(ResultSummary testResult);
|
||||||
|
|
||||||
public static TestResultProcessor BuildChainOfResponsability(TestOptions options)
|
public static TestResultProcessor BuildChainOfResponsability(TestOptions options)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,12 +22,13 @@
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework.Interfaces;
|
using NUnit.Framework.Interfaces;
|
||||||
|
using NUnit.Runner.Helpers;
|
||||||
using PCLStorage;
|
using PCLStorage;
|
||||||
using CreationCollisionOption = PCLStorage.CreationCollisionOption;
|
using CreationCollisionOption = PCLStorage.CreationCollisionOption;
|
||||||
using FileAccess = PCLStorage.FileAccess;
|
using FileAccess = PCLStorage.FileAccess;
|
||||||
|
@ -39,28 +40,28 @@ namespace NUnit.Runner.Services
|
||||||
public XmlFileProcessor(TestOptions options)
|
public XmlFileProcessor(TestOptions options)
|
||||||
: base(options) { }
|
: base(options) { }
|
||||||
|
|
||||||
public override async Task Process(ITestResult testResult)
|
public override async Task Process(ResultSummary result)
|
||||||
{
|
{
|
||||||
if (Options.CreateXmlResultFile)
|
if (Options.CreateXmlResultFile == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
await WriteXmlResultFile(result).ConfigureAwait(false);
|
||||||
{
|
}
|
||||||
await WriteXmlResultFile(testResult).ConfigureAwait(false);
|
catch (Exception)
|
||||||
}
|
{
|
||||||
catch (Exception)
|
Debug.WriteLine("Fatal error while trying to write xml result file!");
|
||||||
{
|
throw;
|
||||||
Debug.WriteLine("Fatal error while trying to write xml result file!");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Successor != null)
|
if (Successor != null)
|
||||||
{
|
{
|
||||||
await Successor.Process(testResult).ConfigureAwait(false);
|
await Successor.Process(result).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task WriteXmlResultFile(ITestResult testResult)
|
async Task WriteXmlResultFile(ResultSummary result)
|
||||||
{
|
{
|
||||||
string outputFolderName = Path.GetDirectoryName(Options.ResultFilePath);
|
string outputFolderName = Path.GetDirectoryName(Options.ResultFilePath);
|
||||||
string outputXmlReportName = Path.GetFileName(Options.ResultFilePath);
|
string outputXmlReportName = Path.GetFileName(Options.ResultFilePath);
|
||||||
|
@ -74,8 +75,8 @@ namespace NUnit.Runner.Services
|
||||||
await outputFolder.CreateFileAsync(outputXmlReportName, CreationCollisionOption.ReplaceExisting);
|
await outputFolder.CreateFileAsync(outputXmlReportName, CreationCollisionOption.ReplaceExisting);
|
||||||
using (var resultFileStream = new StreamWriter(await xmlResultFile.OpenAsync(FileAccess.ReadAndWrite)))
|
using (var resultFileStream = new StreamWriter(await xmlResultFile.OpenAsync(FileAccess.ReadAndWrite)))
|
||||||
{
|
{
|
||||||
string xmlString = testResult.ToXml(true).OuterXml;
|
var xml = result.GetTestXml().ToString();
|
||||||
await resultFileStream.WriteAsync(xmlString);
|
await resultFileStream.WriteAsync(xml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace NUnit.Runner.ViewModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color Color
|
public Color Color
|
||||||
{
|
{
|
||||||
get { return TestResult.Color(); }
|
get { return TestResult.ResultState.Color(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,11 +21,9 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Windows.Input;
|
|
||||||
using NUnit.Framework.Interfaces;
|
using NUnit.Framework.Interfaces;
|
||||||
using NUnit.Runner.View;
|
|
||||||
using Xamarin.Forms;
|
|
||||||
|
|
||||||
namespace NUnit.Runner.ViewModel
|
namespace NUnit.Runner.ViewModel
|
||||||
{
|
{
|
||||||
|
@ -34,13 +32,14 @@ namespace NUnit.Runner.ViewModel
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs the view model
|
/// Constructs the view model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="testResult">The top level test results</param>
|
/// <param name="results">The package of all results in run</param>
|
||||||
/// <param name="viewAll">If true, views all tests, otherwise only shows those
|
/// <param name="viewAll">If true, views all tests, otherwise only shows those
|
||||||
/// that did not pass</param>
|
/// that did not pass</param>
|
||||||
public ResultsViewModel(ITestResult testResult, bool viewAll)
|
public ResultsViewModel(IReadOnlyCollection<ITestResult> results, bool viewAll)
|
||||||
{
|
{
|
||||||
Results = new ObservableCollection<ResultViewModel>();
|
Results = new ObservableCollection<ResultViewModel>();
|
||||||
AddTestResults(testResult, viewAll);
|
foreach (var result in results)
|
||||||
|
AddTestResults(result, viewAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -21,18 +21,11 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using NUnit.Runner.Helpers;
|
||||||
using NUnit.Framework.Api;
|
|
||||||
using NUnit.Framework.Interfaces;
|
|
||||||
using NUnit.Framework.Internal;
|
|
||||||
using NUnit.Runner.View;
|
using NUnit.Runner.View;
|
||||||
using Nunit.Runner.ViewModel;
|
|
||||||
|
|
||||||
using NUnit.Runner.Services;
|
using NUnit.Runner.Services;
|
||||||
|
|
||||||
|
@ -42,20 +35,20 @@ namespace NUnit.Runner.ViewModel
|
||||||
{
|
{
|
||||||
class SummaryViewModel : BaseViewModel
|
class SummaryViewModel : BaseViewModel
|
||||||
{
|
{
|
||||||
readonly IList<Assembly> _testAssemblies;
|
readonly TestPackage _testPackage;
|
||||||
ResultSummary _results;
|
ResultSummary _results;
|
||||||
bool _running;
|
bool _running;
|
||||||
TestResultProcessor _resultProcessor;
|
TestResultProcessor _resultProcessor;
|
||||||
|
|
||||||
public SummaryViewModel()
|
public SummaryViewModel()
|
||||||
{
|
{
|
||||||
_testAssemblies = new List<Assembly>();
|
_testPackage = new TestPackage();
|
||||||
RunTestsCommand = new Command(async o => await ExecuteTestsAync(), o => !Running);
|
RunTestsCommand = new Command(async o => await ExecuteTestsAync(), o => !Running);
|
||||||
ViewAllResultsCommand = new Command(
|
ViewAllResultsCommand = new Command(
|
||||||
async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(Results.TestResult, true))),
|
async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(_results.GetTestResults(), true))),
|
||||||
o => !HasResults);
|
o => !HasResults);
|
||||||
ViewFailedResultsCommand = new Command(
|
ViewFailedResultsCommand = new Command(
|
||||||
async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(Results.TestResult, false))),
|
async o => await Navigation.PushAsync(new ResultsView(new ResultsViewModel(_results.GetTestResults(), false))),
|
||||||
o => !HasResults);
|
o => !HasResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,25 +115,23 @@ namespace NUnit.Runner.ViewModel
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal void AddTest(Assembly testAssembly)
|
internal void AddTest(Assembly testAssembly)
|
||||||
{
|
{
|
||||||
_testAssemblies.Add(testAssembly);
|
_testPackage.AddAssembly(testAssembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task ExecuteTestsAync()
|
async Task ExecuteTestsAync()
|
||||||
{
|
{
|
||||||
Running = true;
|
Running = true;
|
||||||
Results = null;
|
Results = null;
|
||||||
|
TestRunResult results = await _testPackage.ExecuteTests();
|
||||||
var runner = await LoadTestAssembliesAsync().ConfigureAwait(false);
|
ResultSummary summary = new ResultSummary(results);
|
||||||
|
|
||||||
ITestResult result = await Task.Run(() => runner.Run(TestListener.NULL, TestFilter.Empty)).ConfigureAwait(false);
|
|
||||||
|
|
||||||
_resultProcessor = TestResultProcessor.BuildChainOfResponsability(Options);
|
_resultProcessor = TestResultProcessor.BuildChainOfResponsability(Options);
|
||||||
await _resultProcessor.Process(result).ConfigureAwait(false);
|
await _resultProcessor.Process(summary).ConfigureAwait(false);
|
||||||
|
|
||||||
Device.BeginInvokeOnMainThread(
|
Device.BeginInvokeOnMainThread(
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
Results = new ResultSummary(result);
|
Results = summary;
|
||||||
Running = false;
|
Running = false;
|
||||||
|
|
||||||
if (Options.TerminateAfterExecution)
|
if (Options.TerminateAfterExecution)
|
||||||
|
@ -148,14 +139,6 @@ namespace NUnit.Runner.ViewModel
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task<NUnitTestAssemblyRunner> LoadTestAssembliesAsync()
|
|
||||||
{
|
|
||||||
var runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
|
|
||||||
foreach (var testAssembly in _testAssemblies)
|
|
||||||
await Task.Run(() => runner.Load(testAssembly, new Dictionary<string, object>()));
|
|
||||||
return runner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TerminateWithSuccess()
|
public static void TerminateWithSuccess()
|
||||||
{
|
{
|
||||||
#if __IOS__
|
#if __IOS__
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace NUnit.Runner.ViewModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color Color
|
public Color Color
|
||||||
{
|
{
|
||||||
get { return TestResult.Color(); }
|
get { return TestResult.ResultState.Color(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private string StringOrNone(string str)
|
private string StringOrNone(string str)
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\XamarinExtensions.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Extensions\XamarinExtensions.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Helpers\TestRunResult.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Helpers\TestPackage.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\ErrorMessage.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Messages\ErrorMessage.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Properties\Annotations.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Properties\Annotations.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyCommon.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyCommon.cs" />
|
||||||
|
@ -24,7 +26,7 @@
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Services\TestOptions.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Services\TestOptions.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Services\XmlFileProcessor.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Services\XmlFileProcessor.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\BaseViewModel.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\BaseViewModel.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\ResultSummary.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ResultSummary.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\ResultsViewModel.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\ResultsViewModel.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\ResultViewModel.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\ResultViewModel.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\SummaryViewModel.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModel\SummaryViewModel.cs" />
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ImportGroup>
|
<ImportGroup>
|
||||||
<Import Project="$(NuGetPackageRoot)\Xamarin.Forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)\Xamarin.Forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
<Import Project="$(NuGetPackageRoot)xamarin.forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)xamarin.forms\2.3.3.168\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
Загрузка…
Ссылка в новой задаче