Skip to content

Commit

Permalink
Merge pull request #886 from nunit/Issue884
Browse files Browse the repository at this point in the history
Fix for issue #884.  Added ParameterizedFixtures as children of Setup…
  • Loading branch information
OsirisTerje committed Sep 23, 2021
2 parents 31f6c81 + 8661de8 commit 5ce6f1c
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 17 deletions.
6 changes: 3 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#tool vswhere&version=2.7.1
#tool Microsoft.TestPlatform&version=16.9.4
#tool Microsoft.TestPlatform&version=16.11.0

//////////////////////////////////////////////////////////////////////
// ARGUMENTS
Expand All @@ -12,8 +12,8 @@ var configuration = Argument("configuration", "Release");
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////

var version = "4.0.0";
var modifier = "";
var version = "4.1.0";
var modifier = "-alpha01";

var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/Dump/DumpXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void DumpFromVSInput(IGrouping<string, TestCase> testCases, TestFilter f
public void StartDiscoveryInExecution(IGrouping<string, TestCase> testCases, TestFilter filter, TestPackage package)
{
DumpFromVSInput(testCases, filter, package);
AddString($"<NUnitDiscoveryInExecution>{assemblyPath}</NUnitExecution>\n\n");
AddString($"<NUnitDiscoveryInExecution>{assemblyPath}</NUnitDiscoveryInExecution>\n\n");
}

public void StartExecution(TestFilter filter, string atExecution)
Expand Down
38 changes: 25 additions & 13 deletions src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public interface IDiscoveryConverter

public class DiscoveryConverter : IDiscoveryConverter
{
private const string ParameterizedFixture = nameof(ParameterizedFixture);
private const string TestFixture = nameof(TestFixture);
private const string GenericFixture = nameof(GenericFixture);
private const string SetUpFixture = nameof(SetUpFixture);
private const string TestSuite = nameof(TestSuite);

internal static class NUnitXmlAttributeNames
{
public const string Id = "id";
Expand Down Expand Up @@ -187,7 +193,7 @@ private static NUnitDiscoveryTestSuite ExtractTestSuite(XElement node, NUnitDisc
return ts;
}

private void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement node)
private void ExtractAllFixtures(NUnitDiscoveryCanHaveTestFixture parent, XElement node)
{
foreach (var child in node.Elements("test-suite"))
{
Expand All @@ -201,28 +207,28 @@ private void ExtractAllFixtures(NUnitDiscoveryTestSuite parent, XElement node)
var className = child.Attribute(NUnitXmlAttributeNames.Classname)?.Value;
switch (type)
{
case "TestFixture":
case TestFixture:
var tf = ExtractTestFixture(parent, child, className);
parent.AddTestFixture(tf);
ExtractTestCases(tf, child);
ExtractParameterizedMethodsAndTheories(tf, child);
break;
case "GenericFixture":
case GenericFixture:
var gtf = ExtractGenericTestFixture(parent, child);
parent.AddTestGenericFixture(gtf);
ExtractTestFixtures(gtf, child);
break;
case "ParameterizedFixture":
case ParameterizedFixture:
var ptf = ExtractParameterizedTestFixture(parent, child);
parent.AddParameterizedFixture(ptf);
ExtractTestFixtures(ptf, child);
break;
case "SetUpFixture":
case SetUpFixture:
var stf = ExtractSetUpTestFixture(parent, child, className);
parent.AddSetUpFixture(stf);
ExtractTestFixtures(stf, child);
break;
case "TestSuite":
case TestSuite:
var ts = ExtractTestSuite(child, parent);
parent.AddTestSuite(ts);
if (child.HasElements)
Expand All @@ -248,28 +254,36 @@ private void ExtractTestFixtures(NUnitDiscoveryCanHaveTestFixture parent, XEleme
var btf = ExtractSuiteBasePropertiesClass(child);
switch (type)
{
case "TestFixture":
case TestFixture:
var tf = new NUnitDiscoveryTestFixture(btf, className, parent);
parent.AddTestFixture(tf);
ExtractTestCases(tf, child);
ExtractParameterizedMethodsAndTheories(tf, child);
break;
case "TestSuite":
case TestSuite:
var ts = ExtractTestSuite(child, parent);
parent.AddTestSuite(ts);
if (child.HasElements)
ExtractAllFixtures(ts, child);
break;
case "SetUpFixture":
case SetUpFixture:
var tsf = ExtractSetUpTestFixture(parent, node, className);
parent.AddSetUpFixture(tsf);
if (child.HasElements)
{
ExtractTestFixtures(tsf, child);
}
break;
case ParameterizedFixture:
var ptf = ExtractParameterizedTestFixture(parent, node);
parent.AddParameterizedFixture(ptf);
if (child.HasElements)
{
ExtractTestFixtures(ptf, child);
}
break;
default:
throw new DiscoveryException($"Not a TestFixture, SetUpFixture or TestSuite, but {type}");
throw new DiscoveryException($"Not a TestFixture, SetUpFixture, ParameterizedFixture or TestSuite, but {type}");
}
}
}
Expand Down Expand Up @@ -394,9 +408,7 @@ private static BaseProperties ExtractSuiteBasePropertiesClass(XElement node)

foreach (var propnode in node.Elements("properties").Elements("property"))
{
var prop = new NUnitProperty(
propnode.Attribute("name").Value,
propnode.Attribute("value").Value);
var prop = new NUnitProperty(propnode);
bp.Properties.Add(prop);
}
return bp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ title NUnitEngineAdapterClasses for discovery
TestRun o-- Assembly
SetUpFixture o-- TestSuite
SetUpFixture o-- SetUpFixture
SetUpFixture o-- ParameterizedFixture

abstract class SuiteBase {
Property collection,
Expand Down
7 changes: 7 additions & 0 deletions src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Globalization;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Linq;

namespace NUnit.VisualStudio.TestAdapter.NUnitEngine
{
Expand Down Expand Up @@ -198,6 +199,12 @@ public NUnitProperty(string name, string value)
Name = name;
Value = value;
}

public NUnitProperty(XElement node)
{
Name = node.Attribute("name").Value;
Value = node.Attribute("value").Value;
}
}

public class NUnitFailure
Expand Down
44 changes: 44 additions & 0 deletions src/NUnitTestAdapterTests/NUnitEngineTests/NUnitDiscoveryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,50 @@ public void ThatSetUpFixtureWorksIssue824()
Assert.That(ndr, Is.Not.Null);
}

private const string SetupFixtureIssue884 =
@"<test-run id='0' name='NUnitTestAdapterIssueRepro.dll' fullname='d:\repos\NUnit\nunitissues_otherrepos\Issue884\NUnitTestAdapterIssueRepro\bin\Debug\netcoreapp3.1\NUnitTestAdapterIssueRepro.dll' runstate='Runnable' testcasecount='3'>
<test-suite type='Assembly' id='0-1010' name='NUnitTestAdapterIssueRepro.dll' fullname='d:/repos/NUnit/nunitissues_otherrepos/Issue884/NUnitTestAdapterIssueRepro/bin/Debug/netcoreapp3.1/NUnitTestAdapterIssueRepro.dll' runstate='Runnable' testcasecount='3'>
<environment framework-version='3.13.2.0' clr-version='3.1.19' os-version='Microsoft Windows 10.0.19042' platform='Win32NT' cwd='d:\repos\NUnit\nunitissues_otherrepos\Issue884\NUnitTestAdapterIssueRepro\bin\Debug\netcoreapp3.1' machine-name='DESKTOP-SIATMVB' user='TerjeSandstrom' user-domain='AzureAD' culture='en-US' uiculture='en-US' os-architecture='x64' />
<settings>
<setting name='SynchronousEvents' value='False' />
<setting name='InternalTraceLevel' value='Off' />
<setting name='RandomSeed' value='2091732297' />
<setting name='ProcessModel' value='InProcess' />
<setting name='DomainUsage' value='Single' />
<setting name='DefaultTestNamePattern' value='{m}{a}' />
<setting name='WorkDirectory' value='d:\repos\NUnit\nunitissues_otherrepos\Issue884\NUnitTestAdapterIssueRepro\bin\Debug\netcoreapp3.1' />
<setting name='NumberOfTestWorkers' value='28' />
</settings>
<properties>
<property name='_PID' value='36768' />
<property name='_APPDOMAIN' value='testhost' />
</properties>
<test-suite type='SetUpFixture' id='0-1011' name='NUnitTestAdapterIssueRepro' fullname='NUnitTestAdapterIssueRepro.SetupFixture' runstate='Runnable' testcasecount='3'>
<test-suite type='ParameterizedFixture' id='0-1012' name='Tests' fullname='NUnitTestAdapterIssueRepro.Tests' runstate='Runnable' testcasecount='3'>
<test-suite type='TestFixture' id='0-1013' name='Tests(1)' fullname='NUnitTestAdapterIssueRepro.Tests(1)' runstate='Runnable' testcasecount='1'>
<test-case id='0-1002' name='Test1' fullname='NUnitTestAdapterIssueRepro.Tests(1).Test1' methodname='Test1' classname='NUnitTestAdapterIssueRepro.Tests' runstate='Runnable' seed='1282313027' />
</test-suite>
<test-suite type='TestFixture' id='0-1014' name='Tests(2)' fullname='NUnitTestAdapterIssueRepro.Tests(2)' runstate='Runnable' testcasecount='1'>
<test-case id='0-1004' name='Test1' fullname='NUnitTestAdapterIssueRepro.Tests(2).Test1' methodname='Test1' classname='NUnitTestAdapterIssueRepro.Tests' runstate='Runnable' seed='1183073751' />
</test-suite>
<test-suite type='TestFixture' id='0-1015' name='Tests(3)' fullname='NUnitTestAdapterIssueRepro.Tests(3)' runstate='Runnable' testcasecount='1'>
<test-case id='0-1006' name='Test1' fullname='NUnitTestAdapterIssueRepro.Tests(3).Test1' methodname='Test1' classname='NUnitTestAdapterIssueRepro.Tests' runstate='Runnable' seed='1826793735' />
</test-suite>
</test-suite>
</test-suite>
</test-suite>
</test-run>";

[Test]
public void ThatSetUpFixtureWorksIssue884()
{
var sut = new DiscoveryConverter(logger, settings);
var ndr = sut.ConvertXml(
new NUnitResults(XmlHelper.CreateXmlNode(SetupFixtureIssue884)));
Assert.That(ndr, Is.Not.Null);
}


private const string ExtractFixturesHandlesProperties =
@"<test-run id='0' name='Issue824.dll' fullname='d:\repos\NUnit\nunit3-vs-adapter.issues\Issue824\bin\Debug\net5.0\Issue824.dll' runstate='Runnable' testcasecount='2'>
<test-suite type='Assembly' id='0-1012' name='Issue824.dll' fullname='d:/repos/NUnit/nunit3-vs-adapter.issues/Issue824/bin/Debug/net5.0/Issue824.dll' runstate='Runnable' testcasecount='2'>
Expand Down

0 comments on commit 5ce6f1c

Please sign in to comment.