Skip to content

Commit

Permalink
Merge pull request #1 from nirinchev/ni/specific-test-runner
Browse files Browse the repository at this point in the history
Changes required for Realm runner
  • Loading branch information
nirinchev authored Jul 18, 2017
2 parents 9783cc9 + 534d8f3 commit 386aeac
Show file tree
Hide file tree
Showing 44 changed files with 1,007 additions and 258 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,7 @@ tools/*
*project.lock.json

# Android Xamarin
Resource.Designer.cs
Resource.Designer.cs
*.nuget.targets
nunit.runner.userprefs
*.nuget.props
4 changes: 2 additions & 2 deletions src/runner/nunit.runner.Droid/nunit.runner.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;__DROID__</DefineConstants>
<DefineConstants>TRACE;DEBUG;__DROID__;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\nunit.runner.Droid.XML</DocumentationFile>
Expand All @@ -33,7 +33,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;__DROID__</DefineConstants>
<DefineConstants>TRACE;__DROID__;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\nunit.runner.Droid.XML</DocumentationFile>
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions src/runner/nunit.runner.Droid/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"dependencies": {
"NUnit": "3.6.1",
"PCLStorage": "1.0.2",
"Xamarin.Forms": "1.5.0.6447"
"Xamarin.Forms": "2.3.4.224"
},
"frameworks": {
"monoandroid60": {}
"monoandroid71": {}
},
"runtimes": {
"win": {}
Expand Down
3 changes: 2 additions & 1 deletion src/runner/nunit.runner.iOS/nunit.runner.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<DefineConstants>__UNIFIED__;__MOBILE__;__IOS__;DEBUG;TRACE;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
Expand All @@ -29,6 +29,7 @@
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>__UNIFIED__;__MOBILE__;__IOS__;TRACE;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
Expand Down
9 changes: 0 additions & 9 deletions src/runner/nunit.runner.iOS/nunit.runner.iOS.nuget.targets

This file was deleted.

2 changes: 1 addition & 1 deletion src/runner/nunit.runner.iOS/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"NUnit": "3.6.1",
"PCLStorage": "1.0.2",
"Xamarin.Forms": "1.5.0.6447"
"Xamarin.Forms": "2.3.4.224"
},
"frameworks": {
"xamarinios10": {}
Expand Down
9 changes: 0 additions & 9 deletions src/runner/nunit.runner.uwp/nunit.runner.uwp.nuget.targets

This file was deleted.

5 changes: 3 additions & 2 deletions src/runner/nunit.runner.uwp/project.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.3.1",
"NUnit": "3.6.1",
"PCLStorage": "1.0.2",
"Xamarin.Forms": "1.5.0.6447"
"System.Diagnostics.TraceSource": "4.3.0",
"Xamarin.Forms": "2.3.4.224"
},
"frameworks": {
"uap10.0": {}
Expand Down
65 changes: 65 additions & 0 deletions src/runner/nunit.runner/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// ***********************************************************************
// 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.ComponentModel;
using System.Linq;
using NUnit.Framework.Interfaces;

[EditorBrowsable(EditorBrowsableState.Never)]
internal static class EnumerableExtensions
{
internal static IEnumerable<ITest> Flatten(this IEnumerable<ITest> tests)
{
foreach (var test in tests)
{
if (test.Tests.Any())
{
foreach (var child in test.Tests.Flatten())
{
yield return child;
}
}
else
{
yield return test;
}
}
}

internal static IEnumerable<ITestResult> Flatten(this IEnumerable<ITestResult> results)
{
foreach (var result in results)
{
if (result.Children.Any())
{
foreach (var child in result.Children.Flatten())
{
yield return child;
}
}

yield return result;
}
}
}
16 changes: 14 additions & 2 deletions src/runner/nunit.runner/Extensions/XamarinExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

using NUnit.Framework.Interfaces;
using Xamarin.Forms;
using System.Collections.Generic;
using System.Linq;

namespace NUnit.Runner.Extensions
{
Expand All @@ -48,11 +50,21 @@ public static Color Color(this ResultState result)
return Xamarin.Forms.Color.FromRgb(255, 106, 0); // Orange

return Xamarin.Forms.Color.FromRgb(170, 0, 0); // Dark Red

case TestStatus.Inconclusive:
default:
return Xamarin.Forms.Color.Gray;
}
}

public static ResultState OverallResultState(this ITestResult result)
{
if (result.ResultState.Status == TestStatus.Skipped &&
result.Test.IsSuite &&
result.Children.Flatten().Any(c => c.ResultState.Status == TestStatus.Passed))
{
return new ResultState(TestStatus.Passed);
}

return result.ResultState;
}
}
}
68 changes: 32 additions & 36 deletions src/runner/nunit.runner/Helpers/ResultSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ namespace NUnit.Runner.Helpers
/// </summary>
internal class ResultSummary
{
private readonly TestRunResult _results;
public TestRunResult TestResult { get; }
private XDocument _xmlResults;

#region Constructor

public ResultSummary(TestRunResult results)
{
_results = results;
TestResult = results;
Initialize();
Summarize(results.TestResults);
}
Expand All @@ -57,7 +57,7 @@ public ResultSummary(TestRunResult results)
/// <returns></returns>
public IReadOnlyCollection<ITestResult> GetTestResults()
{
return _results.TestResults;
return TestResult.TestResults;
}

/// <summary>
Expand All @@ -82,15 +82,11 @@ public XDocument GetTestXml()

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", TestResult.StartTime.ToString("u")));
test.Add(new XAttribute("end-time", TestResult.EndTime.ToString("u")));
test.Add(new XAttribute("duration", TestResult.Duration.ToString("0.000000", NumberFormatInfo.InvariantInfo)));

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)
foreach (var result in TestResult.TestResults)
test.Add(XElement.Parse(result.ToXml(true).OuterXml));

_xmlResults = new XDocument(test);
Expand Down Expand Up @@ -220,31 +216,31 @@ private void Summarize(ITestResult result)
AssertCount += result.AssertCount;
switch (result.ResultState.Status)
{
case TestStatus.Passed:
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;
case TestStatus.Passed:
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)
Expand Down
Loading

0 comments on commit 386aeac

Please sign in to comment.