From a972f3cd544651de67d132d052f93428510de39a Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Tue, 27 Aug 2024 18:55:40 +0200 Subject: [PATCH 1/3] Change to Central Package Management --- Directory.Packages.props | 32 ++++++++++++ src/Directory.Build.props | 7 --- .../AcceptanceTests.cs | 52 ++++++++++--------- .../CsProjAcceptanceTests.cs | 4 +- .../NUnit.TestAdapter.Tests.Acceptance.csproj | 10 ++-- .../TestSourceWithCustomNames.cs | 2 +- .../Utils.cs | 2 +- .../NUnit3AdapterExternalTests.csproj | 4 +- src/NUnitTestAdapter/CategoryList.cs | 2 +- src/NUnitTestAdapter/NUnit.TestAdapter.csproj | 10 ++-- .../NUnitEngine/DiscoveryConverter.cs | 4 +- .../NUnitEngine/NUnitDiscoveryTestClasses.cs | 22 ++++---- .../NUnitEngine/NUnitTestEvent.cs | 2 +- .../NUnitEngine/NUnitTestNode.cs | 2 +- src/NUnitTestAdapter/NUnitEventListener.cs | 4 +- src/NUnitTestAdapter/TraitsFeature.cs | 2 +- src/NUnitTestAdapterTests/ExecutionTests.cs | 6 +-- .../Fakes/FakeFrameworkHandle.cs | 2 +- .../Fakes/MessageLoggerStub.cs | 2 +- .../NUnit.TestAdapter.Tests.csproj | 25 ++++----- .../NUnit3TestDiscovererTests.cs | 2 +- .../TestDiscoveryTests.cs | 2 +- .../TestExecutionTests.cs | 20 +++---- src/NUnitTestAdapterTests/TraitsTests.cs | 2 +- src/NUnitTestAdapterTests/Utils.cs | 2 +- .../VsExperimentalTests.cs | 2 +- src/empty-assembly/empty-assembly.csproj | 4 +- src/mock-assembly/MockAssembly.cs | 20 ++++++- src/mock-assembly/mock-assembly.csproj | 4 +- 29 files changed, 144 insertions(+), 110 deletions(-) create mode 100644 Directory.Packages.props diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 00000000..94ec682a --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,32 @@ + + + true + false + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 8bbc8c51..4ac08f7a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -9,11 +9,4 @@ true - - - - - - - diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs index 2f778d32..63d66b5b 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs @@ -29,26 +29,26 @@ public abstract class AcceptanceTests public const string LowestNetfxTarget = "net462"; public const string LegacyProjectTargetFrameworkVersion = "v4.6.2"; - protected static IEnumerable TargetFrameworks => new[] - { + protected static IEnumerable TargetFrameworks => + [ LowestNetfxTarget, Frameworks.NetCoreApp31 - }; + ]; - protected static IEnumerable DotNetCliTargetFrameworks => new[] - { + protected static IEnumerable DotNetCliTargetFrameworks => + [ Frameworks.NetCoreApp31, Frameworks.Net50, Frameworks.Net60, Frameworks.Net70 - }; + ]; - protected static IEnumerable ModernDotNetCliTargetFrameworks => new[] - { + protected static IEnumerable ModernDotNetCliTargetFrameworks => + [ Frameworks.Net60, Frameworks.Net70, Frameworks.Net80 - }; + ]; protected static string NUnit3 => "3.*"; protected static string NUnit4 => "4.*"; @@ -58,25 +58,25 @@ public class MultiFrameworkSource public IEnumerable Frameworks { get; set; } = DotNetCliTargetFrameworks; public string NUnitVersion { get; set; } = NUnit3; - public static IEnumerable LegacyDotNetFrameworks => new List { new() }; + public static IEnumerable LegacyDotNetFrameworks => [new()]; - public static IEnumerable ModernDotNetFrameworks => new List - { + public static IEnumerable ModernDotNetFrameworks => + [ new () { Frameworks = ModernDotNetCliTargetFrameworks, NUnitVersion = NUnit4 } - }; + ]; - public static IEnumerable NetFxFrameworks => new List - { + public static IEnumerable NetFxFrameworks => + [ new () { - Frameworks = new List { LowestNetfxTarget }, + Frameworks = [LowestNetfxTarget], NUnitVersion = NUnit4 } - }; + ]; public static IEnumerable AllFrameworks => LegacyDotNetFrameworks.Concat(ModernDotNetFrameworks).Concat(NetFxFrameworks); } @@ -86,10 +86,10 @@ public class SingleFrameworkSource public string Framework { get; set; } = LowestNetfxTarget; public string NUnitVersion { get; set; } = NUnit4; - public static IEnumerable NetFxFramework => new List { new() }; + public static IEnumerable NetFxFramework => [new()]; - public static IEnumerable LegacyDotNetFramework => new List - { + public static IEnumerable LegacyDotNetFramework => + [ new () { Framework = Frameworks.NetCoreApp31, @@ -100,10 +100,10 @@ public class SingleFrameworkSource Framework = Frameworks.Net50, NUnitVersion = NUnit3 } - }; + ]; - public static IEnumerable ModernDotNetFramework => new List - { + public static IEnumerable ModernDotNetFramework => + [ new () { Framework = Frameworks.Net60, @@ -119,7 +119,7 @@ public class SingleFrameworkSource Framework = Frameworks.Net80, NUnitVersion = NUnit4 } - }; + ]; public static IEnumerable AllFrameworks => NetFxFramework.Concat(LegacyDotNetFramework).Concat(ModernDotNetFramework); public static IEnumerable AllFrameworksExceptNetFx => LegacyDotNetFramework.Concat(ModernDotNetFramework); @@ -162,7 +162,7 @@ protected string NUnitVersion(string targetFramework) => downloadCachePath: Path.Combine(directory, ".toolcache")); if (keepWorkspaces) manager.PreserveDirectory("The KeepWorkspaces test parameter was set to true."); - TestContext.WriteLine($"Directory: {directory}, NugetPackageDirectory {nupkgDirectory},NugetPackageVersion: {nupkgVersion}"); + TestContext.Out.WriteLine($"Directory: {directory}, NugetPackageDirectory {nupkgDirectory},NugetPackageVersion: {nupkgVersion}"); return (manager, nupkgVersion, keepWorkspaces); }); @@ -224,7 +224,9 @@ public static void TearDown() } } +#pragma warning disable NUnit1028 // The non-test method is public internal static void OnGlobalTeardown() +#pragma warning restore NUnit1028 // The non-test method is public { if (!Initialization.IsValueCreated) return; diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs index d3c1af7b..e10e7cad 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs @@ -39,9 +39,9 @@ protected IsolatedWorkspace Build() protected void Verify(int executed, int total, VSTestResult results) { - TestContext.WriteLine(" "); + TestContext.Out.WriteLine(" "); foreach (var error in results.RunErrors) - TestContext.WriteLine(error); + TestContext.Out.WriteLine(error); Assert.Multiple(() => { Assert.That(results.Counters.Total, Is.EqualTo(total), diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj b/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj index 8c89ea09..3742586f 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj +++ b/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj @@ -10,13 +10,9 @@ - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs b/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs index 6caf161a..473b713b 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs @@ -89,7 +89,7 @@ public static void Single_target_csproj(SingleFrameworkSource source) " : ""; - TestContext.WriteLine($"Testing {source.Framework}"); + TestContext.Out.WriteLine($"Testing {source.Framework}"); var workspace = CreateWorkspace() .AddProject("Test.csproj", $@" diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs b/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs index ab9e1dc0..b5bfe7e5 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs @@ -104,7 +104,7 @@ public static void DeleteDirectoryRobust(string directory) } catch (IOException ex) when (attempt < 3 && (WinErrorCode)ex.HResult == WinErrorCode.DirNotEmpty) { - TestContext.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying..."); + TestContext.Out.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying..."); } } } diff --git a/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj b/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj index 4726d338..33edc844 100644 --- a/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj +++ b/src/NUnit3AdapterExternalTests/NUnit3AdapterExternalTests.csproj @@ -8,11 +8,11 @@ - + - + \ No newline at end of file diff --git a/src/NUnitTestAdapter/CategoryList.cs b/src/NUnitTestAdapter/CategoryList.cs index 7e31107a..b7224cf0 100644 --- a/src/NUnitTestAdapter/CategoryList.cs +++ b/src/NUnitTestAdapter/CategoryList.cs @@ -57,7 +57,7 @@ public class CategoryList private readonly NUnitProperty explicitTrait = new (ExplicitTraitName, ExplicitTraitValue); - private readonly List categorylist = new (); + private readonly List categorylist = []; private readonly TestCase testCase; private readonly IAdapterSettings settings; private readonly bool showInternalProperties; diff --git a/src/NUnitTestAdapter/NUnit.TestAdapter.csproj b/src/NUnitTestAdapter/NUnit.TestAdapter.csproj index 64119783..185b9203 100644 --- a/src/NUnitTestAdapter/NUnit.TestAdapter.csproj +++ b/src/NUnitTestAdapter/NUnit.TestAdapter.csproj @@ -32,17 +32,17 @@ - - - + + + - + - + diff --git a/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs b/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs index 65ae6940..25bddff6 100644 --- a/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs +++ b/src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs @@ -100,7 +100,7 @@ internal static class NUnitXmlAttributeNames public bool HasExplicitTests => NoOfExplicitTestCases > 0; - private readonly List loadedTestCases = new(); + private readonly List loadedTestCases = []; public IList LoadedTestCases => loadedTestCases; public int NoOfLoadedTestCases => loadedTestCases.Count; @@ -134,7 +134,7 @@ public IEnumerable GetExplicitTestCases(IEnumerable filtered public IList Convert(NUnitResults discoveryResults, string assemblyPath) { if (discoveryResults == null) - return new List(); + return []; AssemblyPath = assemblyPath; var timing = new TimingLogger(Settings, TestLog); if (Settings.DiscoveryMethod != DiscoveryMethod.Legacy) diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs index ee41abb7..3ba82567 100644 --- a/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs +++ b/src/NUnitTestAdapter/NUnitEngine/NUnitDiscoveryTestClasses.cs @@ -105,7 +105,7 @@ public void AddTestAssembly(NUnitDiscoveryTestAssembly testAssembly) public class NUnitDiscoveryProperties { - private List TheProperties { get; } = new(); + private List TheProperties { get; } = []; public IEnumerable Properties => TheProperties; public void Add(NUnitProperty p) => TheProperties.Add(p); @@ -124,7 +124,7 @@ public class NUnitDiscoveryTestSuite(BaseProperties theBase, INUnitDiscoverySuit public sealed class NUnitDiscoveryTestAssembly(BaseProperties theBase, NUnitDiscoveryTestRun parent) : NUnitDiscoveryTestSuite(theBase, parent) { - private readonly List allTestCases = new(); + private readonly List allTestCases = []; /// /// If all testcases are Explicit, we can run this one. @@ -152,12 +152,12 @@ public override void AddToAllTestCases(NUnitDiscoveryTestCase tc) public sealed class NUnitDiscoveryTestFixture(BaseProperties theBase, string classname, INUnitDiscoverySuiteBase parent) : NUnitDiscoveryCanHaveTestCases(theBase, parent, classname) { - private readonly List parameterizedMethods = new(); + private readonly List parameterizedMethods = []; public IEnumerable ParameterizedMethods => parameterizedMethods; - private readonly List theories = new(); + private readonly List theories = []; - private readonly List genericMethods = new(); + private readonly List genericMethods = []; public IEnumerable Theories => theories; public override int NoOfActualTestCases => @@ -257,7 +257,7 @@ public abstract class NUnitDiscoveryCanHaveTestCases( string classname) : NUnitDiscoverySuiteBase(theBase, parent), INUnitDiscoveryCanHaveTestCases { - private readonly List testCases = new(); + private readonly List testCases = []; public IEnumerable TestCases => testCases; public virtual int NoOfActualTestCases => testCases.Count; @@ -284,7 +284,7 @@ public interface INUnitDiscoveryCanHaveTestFixture : INUnitDiscoverySuiteBase public abstract class NUnitDiscoveryCanHaveTestFixture(BaseProperties theBase, INUnitDiscoverySuiteBase parent) : NUnitDiscoverySuiteBase(theBase, parent), INUnitDiscoveryCanHaveTestFixture { - private readonly List testFixtures = new(); + private readonly List testFixtures = []; public IEnumerable TestFixtures => testFixtures; @@ -294,11 +294,11 @@ public void AddTestFixture(NUnitDiscoveryTestFixture tf) } - private readonly List testSuites = new(); + private readonly List testSuites = []; - private readonly List genericFixtures = new(); - private readonly List setUpFixtures = new(); - private readonly List parameterizedFixtures = new(); + private readonly List genericFixtures = []; + private readonly List setUpFixtures = []; + private readonly List parameterizedFixtures = []; public IEnumerable TestSuites => testSuites; diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs index f95da627..10583244 100644 --- a/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs +++ b/src/NUnitTestAdapter/NUnitEngine/NUnitTestEvent.cs @@ -161,7 +161,7 @@ public IEnumerable NUnitAttachments { if (nUnitAttachments != null) return nUnitAttachments; - nUnitAttachments = new List(); + nUnitAttachments = []; foreach (XmlNode attachment in Node.SelectNodes("attachments/attachment")) { var path = attachment.SelectSingleNode("filePath")?.InnerText ?? string.Empty; diff --git a/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs b/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs index a2cd0bc1..48dad9e0 100644 --- a/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs +++ b/src/NUnitTestAdapter/NUnitEngine/NUnitTestNode.cs @@ -21,7 +21,7 @@ public abstract class NUnitTestNode : INUnitTestNode public bool IsNull => Node == null; - private readonly List properties = new (); + private readonly List properties = []; public IEnumerable Properties => properties; public string Seed => Node.GetAttribute("seed"); diff --git a/src/NUnitTestAdapter/NUnitEventListener.cs b/src/NUnitTestAdapter/NUnitEventListener.cs index 0e07de39..7ae01f61 100644 --- a/src/NUnitTestAdapter/NUnitEventListener.cs +++ b/src/NUnitTestAdapter/NUnitEventListener.cs @@ -48,7 +48,7 @@ public class NUnitEventListener(ITestConverterCommon testConverter, INUnit3TestE #endif ITestEventListener, IDisposable // Public for testing { - private static readonly ICollection EmptyNodes = new List(); + private static readonly ICollection EmptyNodes = []; private ITestExecutionRecorder Recorder { get; } = executor.FrameworkHandle; private ITestConverterCommon TestConverter { get; } = testConverter; private IAdapterSettings Settings { get; } = executor.Settings; @@ -235,7 +235,7 @@ public void TestOutput(INUnitTestEventTestOutput outputNodeEvent) { if (!OutputNodes.TryGetValue(testId, out var outputNodes)) { - outputNodes = new List(); + outputNodes = []; OutputNodes.Add(testId, outputNodes); } diff --git a/src/NUnitTestAdapter/TraitsFeature.cs b/src/NUnitTestAdapter/TraitsFeature.cs index bcfb4e87..bc1bb083 100644 --- a/src/NUnitTestAdapter/TraitsFeature.cs +++ b/src/NUnitTestAdapter/TraitsFeature.cs @@ -49,7 +49,7 @@ public sealed class CachedTestCaseInfo /// Currently, the only effect this has is to add a Test Explorer grouping header /// for each trait with the name “Name [Value]”, or for an empty value, “Name”. /// - public List Traits { get; } = new (); + public List Traits { get; } = []; /// /// Used by ; does not affect the Test Explorer UI. diff --git a/src/NUnitTestAdapterTests/ExecutionTests.cs b/src/NUnitTestAdapterTests/ExecutionTests.cs index b56de2f5..533f6796 100644 --- a/src/NUnitTestAdapterTests/ExecutionTests.cs +++ b/src/NUnitTestAdapterTests/ExecutionTests.cs @@ -30,10 +30,10 @@ public void Setup() discovery.NoOfLoadedTestCases.Returns(1); discovery.IsDiscoveryMethodCurrent.Returns(true); - discovery.LoadedTestCases.Returns(new List - { + discovery.LoadedTestCases.Returns( + [ new ("A", new Uri(NUnitTestAdapter.ExecutorUri), "line 23") - }); + ]); filter = new TestFilter("AB"); } diff --git a/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs b/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs index 07608dff..eb3875af 100644 --- a/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs +++ b/src/NUnitTestAdapterTests/Fakes/FakeFrameworkHandle.cs @@ -16,7 +16,7 @@ class FakeFrameworkHandle : IFrameworkHandle public FakeFrameworkHandle() { - Events = new List(); + Events = []; } #endregion diff --git a/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs b/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs index 391aa7ac..733969f6 100644 --- a/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs +++ b/src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs @@ -30,7 +30,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes; public class MessageLoggerStub : IMessageLogger { - private readonly List> messages = new (); + private readonly List> messages = []; public void SendMessage(TestMessageLevel testMessageLevel, string message) { messages.Add(new Tuple(testMessageLevel, message)); diff --git a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj index 8b4e3f16..eab7e5e4 100644 --- a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj +++ b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj @@ -5,37 +5,30 @@ NUnit.VisualStudio.TestAdapter.Tests NUnit.VisualStudio.TestAdapter.Tests net462;netcoreapp3.1 - + + true true latest - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + - + - - - - - - + + + - - + diff --git a/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs b/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs index dcc67002..51befe1b 100644 --- a/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs +++ b/src/NUnitTestAdapterTests/NUnit3TestDiscovererTests.cs @@ -49,7 +49,7 @@ public void ThatDiscovererNUnitEngineAdapterIsInitialized() var sut = new NUnit3TestDiscoverer(); Assert.That(sut.NUnitEngineAdapter, Is.Not.Null); var dc = Substitute.For(); - sut.DiscoverTests(new List(), dc, null, null); + sut.DiscoverTests([], dc, null, null); Assert.That(sut.NUnitEngineAdapter, Is.Not.Null); } } \ No newline at end of file diff --git a/src/NUnitTestAdapterTests/TestDiscoveryTests.cs b/src/NUnitTestAdapterTests/TestDiscoveryTests.cs index f32d713b..e1b6a31c 100644 --- a/src/NUnitTestAdapterTests/TestDiscoveryTests.cs +++ b/src/NUnitTestAdapterTests/TestDiscoveryTests.cs @@ -53,7 +53,7 @@ public class TestDiscoveryTests : ITestCaseDiscoverySink static readonly string MockAssemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "mock-assembly.dll"); - private readonly List testCases = new(); + private readonly List testCases = []; private readonly IDiscoveryContext _context; diff --git a/src/NUnitTestAdapterTests/TestExecutionTests.cs b/src/NUnitTestAdapterTests/TestExecutionTests.cs index 552eeea0..e78f434d 100644 --- a/src/NUnitTestAdapterTests/TestExecutionTests.cs +++ b/src/NUnitTestAdapterTests/TestExecutionTests.cs @@ -45,7 +45,7 @@ public class ResultSummary public ResultSummary(IEnumerable results) { - summary = new Dictionary(); + summary = []; foreach (TestResult result in results) { @@ -103,10 +103,10 @@ public void TestsWhereShouldFilter(string filter, int expectedCount, int noOfSki executor.RunTests(new[] { mockAssemblyPath }, context, fakeFramework); var completedRuns = fakeFramework.Events.Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordEnd).ToList(); - TestContext.WriteLine(" "); + TestContext.Out.WriteLine(" "); foreach (var test in completedRuns) { - TestContext.WriteLine($"{test.TestCase.DisplayName}:{test.TestOutcome}"); + TestContext.Out.WriteLine($"{test.TestCase.DisplayName}:{test.TestOutcome}"); } Assert.Multiple(() => @@ -155,15 +155,15 @@ public void DumpEvents() { foreach (var ev in testLog.Events) { - TestContext.Write(ev.EventType + ": "); + TestContext.Out.Write(ev.EventType + ": "); if (ev.TestResult != null) - TestContext.WriteLine("{0} {1}", ev.TestResult.TestCase.FullyQualifiedName, ev.TestResult.Outcome); + TestContext.Out.WriteLine("{0} {1}", ev.TestResult.TestCase.FullyQualifiedName, ev.TestResult.Outcome); else if (ev.TestCase != null) - TestContext.WriteLine(ev.TestCase.FullyQualifiedName); + TestContext.Out.WriteLine(ev.TestCase.FullyQualifiedName); else if (ev.Message.Text != null) - TestContext.WriteLine(ev.Message.Text); + TestContext.Out.WriteLine(ev.Message.Text); else - TestContext.WriteLine(); + TestContext.Out.WriteLine(); } } @@ -210,8 +210,8 @@ public void CorrectNumberOfResultsWereReceived() [TestCaseSource(nameof(Outcomes))] public int TestOutcomeTotalsAreCorrect(TestOutcome outcome) { - TestContext.WriteLine(" "); - TestContext.WriteLine($"Looking for outcome: {outcome}"); + TestContext.Out.WriteLine(" "); + TestContext.Out.WriteLine($"Looking for outcome: {outcome}"); return testLog.Events .Count(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult && e.TestResult.Outcome == outcome); } diff --git a/src/NUnitTestAdapterTests/TraitsTests.cs b/src/NUnitTestAdapterTests/TraitsTests.cs index 63ea129c..07745c65 100644 --- a/src/NUnitTestAdapterTests/TraitsTests.cs +++ b/src/NUnitTestAdapterTests/TraitsTests.cs @@ -386,7 +386,7 @@ public void SetUp() var settings = Substitute.For(); settings.CollectSourceInformation.Returns(false); testconverter = new TestConverterForXml(testlogger, "whatever", settings); - testcaselist = new List(); + testcaselist = []; } [TearDown] diff --git a/src/NUnitTestAdapterTests/Utils.cs b/src/NUnitTestAdapterTests/Utils.cs index 34f4b313..8891cb0a 100644 --- a/src/NUnitTestAdapterTests/Utils.cs +++ b/src/NUnitTestAdapterTests/Utils.cs @@ -20,7 +20,7 @@ public static void DeleteDirectoryRobust(string directory) } catch (IOException ex) when (attempt < 3 && (WinErrorCode)ex.HResult == WinErrorCode.DirNotEmpty) { - TestContext.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying..."); + TestContext.Out.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying..."); } } } diff --git a/src/NUnitTestAdapterTests/VsExperimentalTests.cs b/src/NUnitTestAdapterTests/VsExperimentalTests.cs index d21ed0c0..98c58b6c 100644 --- a/src/NUnitTestAdapterTests/VsExperimentalTests.cs +++ b/src/NUnitTestAdapterTests/VsExperimentalTests.cs @@ -50,7 +50,7 @@ public void ThatCategoriesAreDistinct() var settings = Substitute.For(); settings.VsTestCategoryType.Returns(VsTestCategoryType.NUnit); var cl = new CategoryList(testCase, settings); - cl.AddRange(new List { "one", "one", "two", "two" }); + cl.AddRange(["one", "one", "two", "two"]); cl.UpdateCategoriesToVs(); var returnedCategoryList = testCase.GetCategories(); diff --git a/src/empty-assembly/empty-assembly.csproj b/src/empty-assembly/empty-assembly.csproj index cd29ed19..40fc46d2 100644 --- a/src/empty-assembly/empty-assembly.csproj +++ b/src/empty-assembly/empty-assembly.csproj @@ -8,11 +8,11 @@ - + - + \ No newline at end of file diff --git a/src/mock-assembly/MockAssembly.cs b/src/mock-assembly/MockAssembly.cs index 28fc1258..a6ff3c25 100644 --- a/src/mock-assembly/MockAssembly.cs +++ b/src/mock-assembly/MockAssembly.cs @@ -130,7 +130,9 @@ public void MockTest3() { Assert.Pass("Succeeded!"); } [Test] +#pragma warning disable NUnit1026 // The test or setup/teardown method is not public protected static void MockTest5() +#pragma warning restore NUnit1026 // The test or setup/teardown method is not public { } [Test] @@ -153,12 +155,14 @@ public void MockTest4() [Category("Special")] public void ExplicitlyRunTest() { } + // ReSharper disable once NUnit.MethodWithParametersAndTestAttribute +#pragma warning disable NUnit1027 // Remove unused parameter [Test] - // ReSharper disable once NUnit.MethodWithParametersAndTestAttribute #pragma warning disable IDE0060 // Remove unused parameter public void NotRunnableTest(int a, int b) #pragma warning restore IDE0060 // Remove unused parameter +#pragma warning restore NUnit1027 { } @@ -246,7 +250,11 @@ public class BadFixture public const int Tests = 1; public const int Suites = 1; +#pragma warning disable IDE0290 // Use primary constructor +#pragma warning disable IDE0060 // Remove unused parameter public BadFixture(int val) { } +#pragma warning restore IDE0060 // Remove unused parameter +#pragma warning restore IDE0290 // Use primary constructor [Test] public void SomeTest() { } @@ -267,7 +275,9 @@ public int MethodWithParameters(int x, int y) [TestCase(2, 4)] [TestCase(9.2, 11.7)] +#pragma warning disable IDE0060 // Remove unused parameter public void GenericMethod(T x, T y) +#pragma warning restore IDE0060 // Remove unused parameter { } } @@ -279,7 +289,11 @@ public class ParameterizedFixture public const int Tests = 4; public const int Suites = 3; +#pragma warning disable IDE0290 // Use primary constructor +#pragma warning disable IDE0060 // Remove unused parameter public ParameterizedFixture(int num) { } +#pragma warning restore IDE0060 // Remove unused parameter +#pragma warning restore IDE0290 // Use primary constructor [Test] public void Test1() { } @@ -298,7 +312,11 @@ public class GenericFixtureConstants [TestFixture(11.5)] public class GenericFixture { +#pragma warning disable IDE0290 // Use primary constructor +#pragma warning disable IDE0060 // Remove unused parameter public GenericFixture(T num) { } +#pragma warning restore IDE0060 // Remove unused parameter +#pragma warning restore IDE0290 // Use primary constructor [Test] public void Test1() { } diff --git a/src/mock-assembly/mock-assembly.csproj b/src/mock-assembly/mock-assembly.csproj index 9feaf8e5..ad03465e 100644 --- a/src/mock-assembly/mock-assembly.csproj +++ b/src/mock-assembly/mock-assembly.csproj @@ -8,11 +8,11 @@ - + - + \ No newline at end of file From 94be89a3ed836222d196a6e72083e1e4a7ac96f0 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Tue, 27 Aug 2024 21:25:56 +0200 Subject: [PATCH 2/3] Fix test error, sdk placed in wrong block --- Directory.Packages.props | 1 + NUnit3TestAdapter.sln | 1 + src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs | 8 ++++---- src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 94ec682a..b8e5f2d3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -17,6 +17,7 @@ all runtime; build; native; contentfiles; analyzers + diff --git a/NUnit3TestAdapter.sln b/NUnit3TestAdapter.sln index 3b2063de..121b3ff5 100644 --- a/NUnit3TestAdapter.sln +++ b/NUnit3TestAdapter.sln @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build.cmd = build.cmd build.ps1 = build.ps1 src\Directory.Build.props = src\Directory.Build.props + Directory.Packages.props = Directory.Packages.props DisableAppDomain.runsettings = DisableAppDomain.runsettings LICENSE = LICENSE src\native-assembly\NativeTests.dll = src\native-assembly\NativeTests.dll diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs index 63d66b5b..fd22f1a7 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs @@ -136,12 +136,12 @@ protected string NUnitVersion(string targetFramework) => private static readonly Lazy<(IsolatedWorkspaceManager Manager, string NupkgVersion, bool KeepWorkspaces)> Initialization = new(() => { var directory = TestContext.Parameters["ProjectWorkspaceDirectory"] - ?? TryAutoDetectProjectWorkspaceDirectory() - ?? throw new InvalidOperationException("The test parameter ProjectWorkspaceDirectory must be set in order to run this test."); + ?? TryAutoDetectProjectWorkspaceDirectory() // Walks the directory tree up to find the project workspace directory, named ".acceptance" + ?? throw new InvalidOperationException("Either The test parameter ProjectWorkspaceDirectory must be set in order to run this test, or the `.acceptance` folder has not been found. Run cmd line `build -t acceptance` first"); var nupkgDirectory = TestContext.Parameters["TestNupkgDirectory"] - ?? TryAutoDetectTestNupkgDirectory(NuGetPackageId) - ?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test."); + ?? TryAutoDetectTestNupkgDirectory(NuGetPackageId) // Walks the directory tree up to find the test nupkg directory, named "package" + ?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test, or the packages have not been created, run cmdline `build -t package` first"); var nupkgVersion = TryGetTestNupkgVersion(nupkgDirectory, packageId: NuGetPackageId) ?? throw new InvalidOperationException($"No NuGet package with the ID {NuGetPackageId} was found in {nupkgDirectory}."); diff --git a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj index eab7e5e4..66a94731 100644 --- a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj +++ b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj @@ -15,6 +15,7 @@ + @@ -23,7 +24,7 @@ - + From c526f48ad1734c3b08fbaf03c142cefce1def96d Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Tue, 27 Aug 2024 21:44:57 +0200 Subject: [PATCH 3/3] Fix CPM affecting acceptance tests --- .../BundledDependencyTests.cs | 2 ++ .../CsProjAcceptanceTests.cs | 1 + .../README.md | 18 ++++++++++++++++++ .../SinglePassingTestResultTests.cs | 4 ++++ .../TestSourceWithCustomNames.cs | 1 + 5 files changed, 26 insertions(+) create mode 100644 src/NUnit.TestAdapter.Tests.Acceptance/README.md diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs index 968c07eb..78838197 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs @@ -14,6 +14,7 @@ public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_ {string.Join(";", TargetFrameworks)} + falsefalse @@ -67,6 +68,7 @@ public static void Engine_uses_its_bundled_version_of_Mono_Cecil_instead_of_the_ {string.Join(";", TargetFrameworks)} + falsefalse diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs index e10e7cad..153cba9b 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs @@ -17,6 +17,7 @@ protected IsolatedWorkspace CreateTestWorkspace(string framework) {framework} + falsefalse diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/README.md b/src/NUnit.TestAdapter.Tests.Acceptance/README.md new file mode 100644 index 00000000..c3fd0b63 --- /dev/null +++ b/src/NUnit.TestAdapter.Tests.Acceptance/README.md @@ -0,0 +1,18 @@ +# How to run the acceptance tests + +## Running the tests by command line + +```cmd +build -t acceptance +``` + +This will build and package the test adapter and run the acceptance tests. + +## Running the tests in Visual Studio + +You can also run the acceptance tests in Visual Studio. +To do this, open the solution in Visual Studio and run the `NUnit.TestAdapter.Tests.Acceptance` Tests from the Test Explorer. + +Note: Running the acceptance tests in Visual Studio require that the package are built and packaged on commandline before running the tests. +This will create the `.acceptance` directory and add the package to the `package` directory. + diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs index 6e79061d..b20de730 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/SinglePassingTestResultTests.cs @@ -47,6 +47,7 @@ private IsolatedWorkspace CreateSingleTargetWorkspace(string fileName, SingleFra {source.Framework} + false @@ -105,6 +106,7 @@ private IsolatedWorkspace CreateMultiTargetWorkspace(string fileName, MultiFrame {string.Join(";", source.Frameworks)} + false @@ -181,6 +183,7 @@ public void Legacy_csproj_with_PackageReference() {LegacyProjectTargetFrameworkVersion} 512 true + falsefalse true @@ -251,6 +254,7 @@ public void Legacy_vbproj_with_PackageReference() Windows {LegacyProjectTargetFrameworkVersion} true + falsefalse true diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs b/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs index 473b713b..fd2d1ad6 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs @@ -96,6 +96,7 @@ public static void Single_target_csproj(SingleFrameworkSource source) {source.Framework} + falsefalse