Skip to content

Commit

Permalink
Merge pull request #859 from nunit/Issue843_Seed
Browse files Browse the repository at this point in the history
Adding output of seeds to logging
  • Loading branch information
OsirisTerje committed May 27, 2021
2 parents 6eed197 + f693241 commit d8095ce
Show file tree
Hide file tree
Showing 10 changed files with 13,101 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -412,3 +412,4 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/dupl.xml
NDependOut/
1 change: 1 addition & 0 deletions .runsettings
Expand Up @@ -3,6 +3,7 @@
<RunConfiguration>
<!-- 0 = As many processes as possible, limited by number of cores on machine, 1 = Sequential (1 process), 2-> Given number of processes up to limit by number of cores on machine-->
<MaxCpuCount>0</MaxCpuCount>

</RunConfiguration>

<!--
Expand Down
13,033 changes: 13,033 additions & 0 deletions NUnit3TestAdapter.ndproj

Large diffs are not rendered by default.

72 changes: 39 additions & 33 deletions src/NUnitTestAdapter/AdapterSettings.cs
Expand Up @@ -296,25 +296,11 @@ public void Load(string settingsXml)
Verbosity = GetInnerTextAsInt(nunitNode, nameof(Verbosity), 0);
_logger.Verbosity = Verbosity;

var runConfiguration = doc.SelectSingleNode("RunSettings/RunConfiguration");
MaxCpuCount = GetInnerTextAsInt(runConfiguration, nameof(MaxCpuCount), -1);
ResultsDirectory = GetInnerTextWithLog(runConfiguration, nameof(ResultsDirectory));
TargetPlatform = GetInnerTextWithLog(runConfiguration, nameof(TargetPlatform));
TargetFrameworkVersion = GetInnerTextWithLog(runConfiguration, nameof(TargetFrameworkVersion));
TestAdapterPaths = GetInnerTextWithLog(runConfiguration, nameof(TestAdapterPaths));
CollectSourceInformation = GetInnerTextAsBool(runConfiguration, nameof(CollectSourceInformation), true);
DisableAppDomain = GetInnerTextAsBool(runConfiguration, nameof(DisableAppDomain), false);
DisableParallelization = GetInnerTextAsBool(runConfiguration, nameof(DisableParallelization), false);
DesignMode = GetInnerTextAsBool(runConfiguration, nameof(DesignMode), false);
CollectDataForEachTestSeparately =
GetInnerTextAsBool(runConfiguration, nameof(CollectDataForEachTestSeparately), false);
ExtractRunConfiguration(doc);

TestProperties = new Dictionary<string, string>();
UpdateTestProperties();
UpdateTestProperties(doc);

// NUnit settings
InternalTraceLevel = GetInnerTextWithLog(nunitNode, nameof(InternalTraceLevel), "Off", "Error", "Warning",
"Info", "Verbose", "Debug");
WorkDirectory = GetInnerTextWithLog(nunitNode, nameof(WorkDirectory));
Where = GetInnerTextWithLog(nunitNode, nameof(Where));
DefaultTimeout = GetInnerTextAsInt(nunitNode, nameof(DefaultTimeout), 0);
Expand All @@ -335,30 +321,23 @@ public void Load(string settingsXml)
UseNUnitIdforTestCaseId = GetInnerTextAsBool(nunitNode, nameof(UseNUnitIdforTestCaseId), false);
ConsoleOut = GetInnerTextAsInt(nunitNode, nameof(ConsoleOut), 1); // 0 no output to console, 1 : output to console
StopOnError = GetInnerTextAsBool(nunitNode, nameof(StopOnError), false);
DiscoveryMethod = MapEnum(GetInnerText(nunitNode, nameof(DiscoveryMethod), Verbosity > 0), DiscoveryMethod.Current);
UseNUnitFilter = GetInnerTextAsBool(nunitNode, nameof(UseNUnitFilter), true);


// Engine settings
DiscoveryMethod = MapEnum(GetInnerText(nunitNode, nameof(DiscoveryMethod), Verbosity > 0), DiscoveryMethod.Current);
SkipNonTestAssemblies = GetInnerTextAsBool(nunitNode, nameof(SkipNonTestAssemblies), true);
AssemblySelectLimit = GetInnerTextAsInt(nunitNode, nameof(AssemblySelectLimit), 2000);


// Adapter Diagnostics
DumpXmlTestDiscovery = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestDiscovery), false);
DumpXmlTestResults = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestResults), false);
DumpVsInput = GetInnerTextAsBool(nunitNode, nameof(DumpVsInput), false);
FreakMode = GetInnerTextAsBool(nunitNode, nameof(FreakMode), false);
// End Diagnostics
ExtractNUnitDiagnosticSettings(nunitNode);

// Adapter Display Options
MapDisplayName(GetInnerText(nunitNode, nameof(DisplayName), Verbosity > 0));
FullnameSeparator = GetInnerText(nunitNode, nameof(FullnameSeparator), Verbosity > 0)?[0] ?? ':';

// EndDisplay



PreFilter = GetInnerTextAsBool(nunitNode, nameof(PreFilter), false);
MapTestCategory(GetInnerText(nunitNode, nameof(VsTestCategoryType), Verbosity > 0));
MapWarningTo = MapWarningOutcome(GetInnerText(nunitNode, nameof(MapWarningTo), Verbosity > 0));
Expand Down Expand Up @@ -399,19 +378,46 @@ public void Load(string settingsXml)

// Update NumberOfTestWorkers based on the DisableParallelization and NumberOfTestWorkers from runsettings.
UpdateNumberOfTestWorkers();
}

private void ExtractNUnitDiagnosticSettings(XmlNode nunitNode)
{
DumpXmlTestDiscovery = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestDiscovery), false);
DumpXmlTestResults = GetInnerTextAsBool(nunitNode, nameof(DumpXmlTestResults), false);
DumpVsInput = GetInnerTextAsBool(nunitNode, nameof(DumpVsInput), false);
FreakMode = GetInnerTextAsBool(nunitNode, nameof(FreakMode), false);
InternalTraceLevel = GetInnerTextWithLog(nunitNode, nameof(InternalTraceLevel), "Off", "Error", "Warning",
"Info", "Verbose", "Debug");
}

void UpdateTestProperties()
private void UpdateTestProperties(XmlDocument doc)
{
TestProperties = new Dictionary<string, string>();
foreach (XmlNode node in doc.SelectNodes("RunSettings/TestRunParameters/Parameter"))
{
foreach (XmlNode node in doc.SelectNodes("RunSettings/TestRunParameters/Parameter"))
{
var key = node.GetAttribute("name");
var value = node.GetAttribute("value");
if (key != null && value != null)
TestProperties.Add(key, value);
}
var key = node.GetAttribute("name");
var value = node.GetAttribute("value");
if (key != null && value != null)
TestProperties.Add(key, value);
}
}

private void ExtractRunConfiguration(XmlDocument doc)
{
var runConfiguration = doc.SelectSingleNode("RunSettings/RunConfiguration");
MaxCpuCount = GetInnerTextAsInt(runConfiguration, nameof(MaxCpuCount), -1);
ResultsDirectory = GetInnerTextWithLog(runConfiguration, nameof(ResultsDirectory));
TargetPlatform = GetInnerTextWithLog(runConfiguration, nameof(TargetPlatform));
TargetFrameworkVersion = GetInnerTextWithLog(runConfiguration, nameof(TargetFrameworkVersion));
TestAdapterPaths = GetInnerTextWithLog(runConfiguration, nameof(TestAdapterPaths));
CollectSourceInformation = GetInnerTextAsBool(runConfiguration, nameof(CollectSourceInformation), true);
DisableAppDomain = GetInnerTextAsBool(runConfiguration, nameof(DisableAppDomain), false);
DisableParallelization = GetInnerTextAsBool(runConfiguration, nameof(DisableParallelization), false);
DesignMode = GetInnerTextAsBool(runConfiguration, nameof(DesignMode), false);
CollectDataForEachTestSeparately =
GetInnerTextAsBool(runConfiguration, nameof(CollectDataForEachTestSeparately), false);
}

private void MapTestCategory(string vsTestCategoryType)
{
if (vsTestCategoryType == null)
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitTestAdapter/CategoryList.cs
Expand Up @@ -55,9 +55,9 @@ public class CategoryList
// If it's not empty, it shows up as “Explicit [value]” in Test Explorer.
private const string ExplicitTraitValue = "";

private readonly NUnitProperty explicitTrait = new NUnitProperty(ExplicitTraitName, ExplicitTraitValue);
private readonly NUnitProperty explicitTrait = new (ExplicitTraitName, ExplicitTraitValue);

private readonly List<string> categorylist = new List<string>();
private readonly List<string> categorylist = new ();
private readonly TestCase testCase;
private readonly IAdapterSettings settings;
private readonly bool showInternalProperties;
Expand Down
6 changes: 5 additions & 1 deletion src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs
Expand Up @@ -9,6 +9,7 @@ public interface INUnitTestNode
string FullName { get; }
string Name { get; }
IEnumerable<NUnitProperty> Properties { get; }
string Seed { get; }
}

public abstract class NUnitTestNode : INUnitTestNode
Expand All @@ -17,10 +18,13 @@ public abstract class NUnitTestNode : INUnitTestNode
public virtual string Id => Node.GetAttribute("id");
public string FullName => Node.GetAttribute("fullname");
public string Name => Node.GetAttribute("name");

public bool IsNull => Node == null;

private readonly List<NUnitProperty> properties = new List<NUnitProperty>();
private readonly List<NUnitProperty> properties = new ();
public IEnumerable<NUnitProperty> Properties => properties;
public string Seed => Node.GetAttribute("seed");

protected NUnitTestNode(XmlNode node)
{
Node = node;
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitTestAdapter/Properties/AssemblyInfo.cs
@@ -1,5 +1,5 @@
// ****************************************************************
// Copyright (c) 2011-2020 Charlie Poole, Terje Sandstrom.
// Copyright (c) 2011-2021 Charlie Poole, Terje Sandstrom.
// ****************************************************************

using System;
Expand All @@ -12,7 +12,7 @@
[assembly: AssemblyDescription("A package containing the NUnit 3 TestAdapter for Visual Studio 2012 onwards. With this package you don't need to install the VSIX adapter package, and you don't need to upload the adapter to your Azure DevOps server.\r\n \r\nNote that this package ONLY contains the adapter, not the NUnit framework. You must also get the framework. You only need one such package for a solution. \r\n\r\nThe package works with Visual Studio 2012 and newer.\r\n")]
[assembly: AssemblyCompany("NUnit Project")]
[assembly: AssemblyProduct("NUnit3TestAdapter")]
[assembly: AssemblyCopyright("Copyright © 2011-2020 Charlie Poole, 2014-2020 Terje Sandstrom")]
[assembly: AssemblyCopyright("Copyright © 2011-2021 Charlie Poole, 2014-2021 Terje Sandstrom")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: CLSCompliant(false)]
Expand Down
11 changes: 11 additions & 0 deletions src/NUnitTestAdapter/Seed.cs
@@ -0,0 +1,11 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

namespace NUnit.VisualStudio.TestAdapter
{
public class Seed
{
internal static readonly TestProperty NUnitSeedProperty = TestProperty.Register(
"NUnit.Seed",
"Seed", typeof(string), TestPropertyAttributes.None, typeof(TestCase));
}
}
6 changes: 6 additions & 0 deletions src/NUnitTestAdapter/TestConverter.cs
Expand Up @@ -209,6 +209,7 @@ private TestCase MakeTestCaseFromDiscoveryNode(NUnitDiscoveryTestCase testNode)
}

testCase.AddTraitsFromTestNode(testNode, TraitsCache, _logger, adapterSettings);
testCase.SetPropertyValue(Seed.NUnitSeedProperty, testNode.Seed.ToString());

return testCase;

Expand Down Expand Up @@ -299,6 +300,11 @@ private VSTestResult GetBasicResult(INUnitTestEvent resultNode, IEnumerable<INUn
vsResult.Duration = TimeSpan.FromTicks(1);

vsResult.ComputerName = Environment.MachineName;
vsResult.SetPropertyValue(Seed.NUnitSeedProperty, resultNode.Seed);
if (adapterSettings.Verbosity >= 5)
{
vsResult.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, $"seed: {resultNode.Seed}"));
}

FillResultFromOutputNodes(outputNodes, vsResult);

Expand Down
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/VsTestFilter.cs
Expand Up @@ -62,7 +62,7 @@ static VsTestFilter()
["FullyQualifiedName"] = TestCaseProperties.FullyQualifiedName,
["Name"] = TestCaseProperties.DisplayName,
["TestCategory"] = CategoryList.NUnitTestCategoryProperty,
["Category"] = CategoryList.NUnitTestCategoryProperty
["Category"] = CategoryList.NUnitTestCategoryProperty,
};
// Initialize the trait cache
var priorityTrait = new NTrait("Priority", "");
Expand Down

0 comments on commit d8095ce

Please sign in to comment.