diff --git a/NUnitConsole.sln b/NUnitConsole.sln index 8e9350066..f8919dc54 100644 --- a/NUnitConsole.sln +++ b/NUnitConsole.sln @@ -66,6 +66,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "runners", "runners", "{F3E8 ProjectSection(SolutionItems) = preProject nuget\runners\DotnetToolSettings.xml = nuget\runners\DotnetToolSettings.xml nuget\runners\nunit.console-runner-with-extensions.nuspec = nuget\runners\nunit.console-runner-with-extensions.nuspec + nuget\runners\nunit.console-runner.net80.nuspec = nuget\runners\nunit.console-runner.net80.nuspec nuget\runners\nunit.console-runner.netcore.nuspec = nuget\runners\nunit.console-runner.netcore.nuspec nuget\runners\nunit.console-runner.nuspec = nuget\runners\nunit.console-runner.nuspec nuget\runners\nunit.console.nuget.addins = nuget\runners\nunit.console.nuget.addins @@ -146,6 +147,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InvalidTestNames", "src\Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppContextTest", "src\TestData\AppContextTest\AppContextTest.csproj", "{E43A3E4B-B050-471B-B43C-0DF60FD44376}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net8.0", "net8.0", "{303CF83E-2A87-4882-8CAC-3EB59AAD81FC}" + ProjectSection(SolutionItems) = preProject + nuget\runners\net8.0\DotnetToolSettings.xml = nuget\runners\net8.0\DotnetToolSettings.xml + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -258,6 +264,7 @@ Global {6B550F25-1CA5-4F3E-B631-1ECCD4CB94E4} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} {58E18ACC-1F7E-4395-817E-E7EF943E0C77} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} {E43A3E4B-B050-471B-B43C-0DF60FD44376} = {2ECE1CFB-9436-4149-B7E4-1FB1786FDE9F} + {303CF83E-2A87-4882-8CAC-3EB59AAD81FC} = {F3E87D0F-6F06-4C0B-AE06-42C0834C3C6E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D8E4FC26-5422-4C51-8BBC-D1AC0A578711} diff --git a/build.cake b/build.cake index 7be220651..ed7f68201 100644 --- a/build.cake +++ b/build.cake @@ -45,6 +45,7 @@ FilePath[] AGENT_PDB_FILES_NETCORE = { PackageDefinition NUnitConsoleNuGetPackage; PackageDefinition NUnitConsoleRunnerNuGetPackage; PackageDefinition NUnitConsoleRunnerNetCorePackage; +PackageDefinition NUnitConsoleRunnerNet80Package; PackageDefinition NUnitEnginePackage; PackageDefinition NUnitEngineApiPackage; PackageDefinition NUnitConsoleRunnerChocolateyPackage; @@ -90,6 +91,14 @@ BuildSettings.Packages.AddRange(new PackageDefinition[] { + $"NUnit.ConsoleRunner.NetCore.{BuildSettings.PackageVersion}/nunit.exe"), tests: NetCoreRunnerTests), + NUnitConsoleRunnerNet80Package = new DotNetToolPackage( + id: "NUnit.ConsoleRunner.Net80", + source: BuildSettings.NuGetDirectory + "runners/nunit.console-runner.net80.nuspec", + checks: new PackageCheck[] { HasFiles("nunit-net80.exe") }, + testRunner: new ConsoleRunnerSelfTester(BuildSettings.NuGetTestDirectory + + $"NUnit.ConsoleRunner.Net80.{BuildSettings.PackageVersion}/nunit-net80.exe"), + tests: NetCoreRunnerTests), + NUnitConsoleRunnerChocolateyPackage = new ChocolateyPackage( id: "nunit-console-runner", source: BuildSettings.ChocolateyDirectory + "nunit-console-runner.nuspec", diff --git a/nuget/runners/net8.0/DotnetToolSettings.xml b/nuget/runners/net8.0/DotnetToolSettings.xml new file mode 100644 index 000000000..e49f98228 --- /dev/null +++ b/nuget/runners/net8.0/DotnetToolSettings.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/nuget/runners/nunit.console-runner.net80.nuspec b/nuget/runners/nunit.console-runner.net80.nuspec new file mode 100644 index 000000000..00b997e5b --- /dev/null +++ b/nuget/runners/nunit.console-runner.net80.nuspec @@ -0,0 +1,53 @@ + + + + NUnit.ConsoleRunner.Net80 + NUnit Console Runner (.NET 8.0) + $version$ + Charlie Poole, Rob Prouse + Charlie Poole, Rob Prouse + LICENSE.txt + https://nunit.org + + https://cdn.rawgit.com/nunit/resources/master/images/icon/nunit_256.png + images\nunit_256.png + false + .NET Core build of the console runner for the NUnit unit-testing framework. + + This package includes the .NET 8.0 build of the NUnit console runner and test engine. + + Any extensions, if needed, may be installed as separate packages. + + https://docs.nunit.org/articles/nunit/release-notes/console-and-engine.html + en-US + nunit test testing tdd runner + Copyright (c) 2021-2024 Charlie Poole, Rob Prouse + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/NUnitEngine/nunit.engine.core.tests/Services/DriverServiceTests.cs b/src/NUnitEngine/nunit.engine.core.tests/Services/DriverServiceTests.cs index cb76a3872..e7a2ab637 100644 --- a/src/NUnitEngine/nunit.engine.core.tests/Services/DriverServiceTests.cs +++ b/src/NUnitEngine/nunit.engine.core.tests/Services/DriverServiceTests.cs @@ -30,37 +30,63 @@ public void ServiceIsStarted() Assert.That(_driverService.Status, Is.EqualTo(ServiceStatus.Started), "Failed to start service"); } + [TestCaseSource(nameof(DriverSelectionTestCases))] + public void CorrectDriverIsUsed(string fileName, bool skipNonTestAssemblies, Type expectedType) + { + var driver = _driverService.GetDriver(AppDomain.CurrentDomain, Path.Combine(TestContext.CurrentContext.TestDirectory, fileName), null, skipNonTestAssemblies); + Assert.That(driver, Is.InstanceOf(expectedType)); + } -#if NET5_0_OR_GREATER - [TestCase("mock-assembly.dll", false, typeof(NUnitNetCore31Driver))] - [TestCase("mock-assembly.dll", true, typeof(NUnitNetCore31Driver))] - //[TestCase("notest-assembly.dll", false, typeof(NUnitNetCore31Driver))] + static TestCaseData[] DriverSelectionTestCases = new[] + { +#if NETFRAMEWORK + new TestCaseData("mock-assembly.dll", false, typeof(NUnit3FrameworkDriver)), + new TestCaseData("mock-assembly.dll", true, typeof(NUnit3FrameworkDriver)), + new TestCaseData("notest-assembly.dll", false, typeof(NUnit3FrameworkDriver)), +#elif NET5_0_OR_GREATER + new TestCaseData("mock-assembly.dll", false, typeof(NUnitNetCore31Driver)), + new TestCaseData("mock-assembly.dll", true, typeof(NUnitNetCore31Driver)), + //new TestCaseData("notest-assembly.dll", false, typeof(NUnitNetCore31Driver)), #elif NETCOREAPP3_1 - [TestCase("mock-assembly.dll", false, typeof(NUnitNetCore31Driver))] - [TestCase("mock-assembly.dll", true, typeof(NUnitNetCore31Driver))] - [TestCase("notest-assembly.dll", false, typeof(NUnitNetCore31Driver))] + new TestCaseData("mock-assembly.dll", false, typeof(NUnitNetCore31Driver)), + new TestCaseData("mock-assembly.dll", true, typeof(NUnitNetCore31Driver)), + new TestCaseData("notest-assembly.dll", false, typeof(NUnitNetCore31Driver)), +// TODO: This is never used. We need to test net standard driver in some way, possibly +// by forcing it's use in a separate test. #elif NETCOREAPP2_1 - [TestCase("mock-assembly.dll", false, typeof(NUnitNetStandardDriver))] - [TestCase("mock-assembly.dll", true, typeof(NUnitNetStandardDriver))] - [TestCase("notest-assembly.dll", false, typeof(NUnitNetStandardDriver))] -#else - [TestCase("mock-assembly.dll", false, typeof(NUnit3FrameworkDriver))] - [TestCase("mock-assembly.dll", true, typeof(NUnit3FrameworkDriver))] - [TestCase("notest-assembly.dll", false, typeof(NUnit3FrameworkDriver))] -#endif - [TestCase("mock-assembly.pdb", false, typeof(InvalidAssemblyFrameworkDriver))] - [TestCase("mock-assembly.pdb", true, typeof(InvalidAssemblyFrameworkDriver))] - [TestCase("junk.dll", false, typeof(InvalidAssemblyFrameworkDriver))] - [TestCase("junk.dll", true, typeof(InvalidAssemblyFrameworkDriver))] - [TestCase("nunit.engine.core.dll", false, typeof(InvalidAssemblyFrameworkDriver))] - [TestCase("nunit.engine.core.dll", true, typeof(SkippedAssemblyFrameworkDriver))] -#if !NET5_0_OR_GREATER // Not yet working - [TestCase("notest-assembly.dll", true, typeof(SkippedAssemblyFrameworkDriver))] + new TestCaseData("mock-assembly.dll", false, typeof(NUnitNetStandardDriver)), + new TestCaseData("mock-assembly.dll", true, typeof(NUnitNetStandardDriver)), + new TestCaseData("notest-assembly.dll", false, typeof(NUnitNetStandardDriver)), #endif - public void CorrectDriverIsUsed(string fileName, bool skipNonTestAssemblies, Type expectedType) +// Invalid cases should work with all target runtimes + new TestCaseData("mock-assembly.pdb", false, typeof(InvalidAssemblyFrameworkDriver)), + new TestCaseData("mock-assembly.pdb", true, typeof(InvalidAssemblyFrameworkDriver)), + new TestCaseData("junk.dll", false, typeof(InvalidAssemblyFrameworkDriver)), + new TestCaseData("junk.dll", true, typeof(InvalidAssemblyFrameworkDriver)), + new TestCaseData("nunit.engine.core.dll", false, typeof(InvalidAssemblyFrameworkDriver)), + new TestCaseData("nunit.engine.core.dll", true, typeof(SkippedAssemblyFrameworkDriver)) +//#if !NET5_0_OR_GREATER // Not yet working +// new TestCaseData"notest-assembly.dll", true, typeof(SkippedAssemblyFrameworkDriver)) +//#endif + }; + + [Test] + public void EnsureWeHaveSomeValidTestCases() { - var driver = _driverService.GetDriver(AppDomain.CurrentDomain, Path.Combine(TestContext.CurrentContext.TestDirectory, fileName), null, skipNonTestAssemblies); - Assert.That(driver, Is.InstanceOf(expectedType)); + // We currently build these tests for net462, net 8.0, net 6.0 and net core 3.1. + // This test is needed because of the conditional compilation used in generating + // the test cases. If the test project is updated to add a new target runtime, + // and no test cases are added for that runtime, this test will fail. + foreach (var testcase in DriverSelectionTestCases) + { + // Third argument is the Type of the driver + var driverType = testcase.Arguments[2] as Type; + if (!(driverType.BaseType == typeof(NotRunnableFrameworkDriver))) + break; + + // All expected drivers derive from NotRunnableFrameworkDriver + Assert.Fail("Only invalid test cases were provided for this runtime. Update DriverServiceTests.cs to include some valid cases."); + } } } } diff --git a/src/NUnitEngine/nunit.engine/Services/RuntimeLocators/NetCoreRuntimeLocator.cs b/src/NUnitEngine/nunit.engine/Services/RuntimeLocators/NetCoreRuntimeLocator.cs index 333e5db7b..9e94709b6 100644 --- a/src/NUnitEngine/nunit.engine/Services/RuntimeLocators/NetCoreRuntimeLocator.cs +++ b/src/NUnitEngine/nunit.engine/Services/RuntimeLocators/NetCoreRuntimeLocator.cs @@ -70,7 +70,7 @@ private static IEnumerable GetRuntimeList() } catch (Exception) { - // Failed to start dotnet command. Assume no versions are installed and just r eturn just return + // Failed to start dotnet command. Assume no versions are installed and just return yield break; }