Skip to content

Commit

Permalink
Merge pull request #1092 from nunit/issue-1075
Browse files Browse the repository at this point in the history
Separate nunit.engine.core.tests from nunit.engine.tests
  • Loading branch information
CharliePoole authored Jan 15, 2022
2 parents 7472346 + 3cda91a commit cb020f4
Show file tree
Hide file tree
Showing 46 changed files with 232 additions and 52 deletions.
7 changes: 7 additions & 0 deletions NUnitConsole.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "zip", "zip", "{20005864-BE8
zip\nunit.bundle.addins = zip\nunit.bundle.addins
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.engine.core.tests", "src\NUnitEngine\nunit.engine.core.tests\nunit.engine.core.tests.csproj", "{CACC0520-B452-4310-A33C-DC944129ACDD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -182,6 +184,10 @@ Global
{9D3015EE-5B84-41B3-A1D3-1A439370C392}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D3015EE-5B84-41B3-A1D3-1A439370C392}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D3015EE-5B84-41B3-A1D3-1A439370C392}.Release|Any CPU.Build.0 = Release|Any CPU
{CACC0520-B452-4310-A33C-DC944129ACDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CACC0520-B452-4310-A33C-DC944129ACDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CACC0520-B452-4310-A33C-DC944129ACDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CACC0520-B452-4310-A33C-DC944129ACDD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -207,6 +213,7 @@ Global
{9BCA00E2-D072-424B-A6DF-5BECF719C1FB} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF}
{0C0D20CE-70CD-4CEF-BE9B-AEB8A2DE9C8A} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF}
{20005864-BE82-412D-99BF-288E2D8370E9} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF}
{CACC0520-B452-4310-A33C-DC944129ACDD} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D8E4FC26-5422-4C51-8BBC-D1AC0A578711}
Expand Down
96 changes: 92 additions & 4 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void BuildUsingMSBuildOnWindowsOrMacOS()
.WithProperty("TargetFramework", framework)
.WithProperty("PublishDir", BIN_DIR + framework));

foreach (var framework in new[] { "netcoreapp2.1", "netcoreapp3.1", "net5.0" })
foreach (var framework in new[] { "netcoreapp2.1", "netcoreapp3.1" })
MSBuild(ENGINE_TESTS_PROJECT, CreateMSBuildSettings("Publish")
.WithProperty("TargetFramework", framework)
.WithProperty("PublishDir", BIN_DIR + framework));
Expand All @@ -154,7 +154,8 @@ private void BuildEachProjectSeparatelyOnLinux()
BuildProject(AGENT_PROJECT, "net20", "net40", "netcoreapp3.1", "net5.0");
BuildProject(AGENT_X86_PROJECT, "net20", "net40");

BuildProject(ENGINE_TESTS_PROJECT, "net35", "netcoreapp2.1", "netcoreapp3.1", "net5.0");
BuildProject(ENGINE_TESTS_PROJECT, "net35", "netcoreapp2.1", "netcoreapp3.1");
BuildProject(ENGINE_CORE_TESTS_PROJECT, "net35", "netcoreapp2.1", "netcoreapp3.1", "net5.0");
BuildProject(CONSOLE_TESTS_PROJECT, "net35", "netcoreapp3.1");

BuildProject(MOCK_ASSEMBLY_X86_PROJECT, "net35", "net40", "netcoreapp2.1", "netcoreapp3.1");
Expand All @@ -170,6 +171,9 @@ private void BuildEachProjectSeparatelyOnLinux()
MSBuild(ENGINE_TESTS_PROJECT, CreateMSBuildSettings("Publish")
.WithProperty("TargetFramework", "netcoreapp2.1")
.WithProperty("PublishDir", BIN_DIR + "netcoreapp2.1"));
MSBuild(ENGINE_CORE_TESTS_PROJECT, CreateMSBuildSettings("Publish")
.WithProperty("TargetFramework", "netcoreapp2.1")
.WithProperty("PublishDir", BIN_DIR + "netcoreapp2.1"));
}

// NOTE: If we use DotNet to build on Linux, then our net35 projects fail.
Expand Down Expand Up @@ -224,6 +228,82 @@ Task("CheckForTestErrors")
.Description("Checks for errors running the test suites")
.Does(() => DisplayUnreportedErrors());

//////////////////////////////////////////////////////////////////////
// TEST .NET 2.0 ENGINE CORE
//////////////////////////////////////////////////////////////////////

Task("TestNet20EngineCore")
.Description("Tests the engine core assembly")
.IsDependentOn("Build")
.OnError(exception => { UnreportedErrors.Add(exception.Message); })
.Does(() =>
{
RunTest(
NET20_CONSOLE,
BIN_DIR + "net35/",
ENGINE_CORE_TESTS,
"net35",
ref UnreportedErrors);
});

//////////////////////////////////////////////////////////////////////
// TEST NETSTANDARD 2.0 ENGINE CORE
//////////////////////////////////////////////////////////////////////

Task("TestNetStandard20EngineCore")
.Description("Tests the .NET Standard Engine core assembly")
.IsDependentOn("Build")
.OnError(exception => { UnreportedErrors.Add(exception.Message); })
.Does(() =>
{
RunDotnetCoreNUnitLiteTests(
BIN_DIR + "netcoreapp2.1/" + ENGINE_CORE_TESTS,
BIN_DIR + "netcoreapp2.1",
"netcoreapp2.1",
ref UnreportedErrors);
});

//////////////////////////////////////////////////////////////////////
// TEST NETCORE 3.1 ENGINE CORE
//////////////////////////////////////////////////////////////////////

Task("TestNetCore31EngineCore")
.Description("Tests the .NET Core 3.1 Engine core assembly")
.IsDependentOn("Build")
.OnError(exception => { UnreportedErrors.Add(exception.Message); })
.Does(() =>
{
var runtimes = new[] { "3.1", "5.0" };

foreach (var runtime in runtimes)
{
RunDotnetCoreTests(
NETCORE31_CONSOLE,
BIN_DIR + "netcoreapp3.1/",
ENGINE_CORE_TESTS,
runtime,
ref UnreportedErrors);
}
});

//////////////////////////////////////////////////////////////////////
// TEST NET 5.0 ENGINE CORE
//////////////////////////////////////////////////////////////////////

Task("TestNet50EngineCore")
.Description("Tests the .NET 5.0 Engine core assembly")
.IsDependentOn("Build")
.OnError(exception => { UnreportedErrors.Add(exception.Message); })
.Does(() =>
{
RunDotnetCoreTests(
NETCORE31_CONSOLE,
BIN_DIR + "net5.0",
ENGINE_CORE_TESTS,
"net5.0",
ref UnreportedErrors);
});

//////////////////////////////////////////////////////////////////////
// TEST .NET 2.0 ENGINE
//////////////////////////////////////////////////////////////////////
Expand All @@ -238,7 +318,7 @@ Task("TestNet20Engine")
NET20_CONSOLE,
BIN_DIR + "net35/",
ENGINE_TESTS,
"net35",
"net35",
ref UnreportedErrors);
});

Expand Down Expand Up @@ -715,14 +795,22 @@ Task("TestConsole")
.IsDependentOn("TestNet20Console")
.IsDependentOn("TestNetCore31Console");

Task("TestEngineCore")
.Description("Builds and tests the engine core assembly")
.IsDependentOn("TestNet20EngineCore")
.IsDependentOn("TestNetStandard20EngineCore")
.IsDependentOn("TestNetCore31EngineCore")
.IsDependentOn("TestNet50EngineCore");

Task("TestEngine")
.Description("Builds and tests the engine")
.Description("Builds and tests the engine assembly")
.IsDependentOn("TestNet20Engine")
.IsDependentOn("TestNetStandard20Engine")
.IsDependentOn("TestNetCore31Engine");

Task("Test")
.Description("Builds and tests the engine and console runner")
.IsDependentOn("TestEngineCore")
.IsDependentOn("TestEngine")
.IsDependentOn("TestConsole")
.IsDependentOn("CheckForTestErrors");
Expand Down
4 changes: 3 additions & 1 deletion cake/constants.cake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var AGENT_X86_PROJECT = SOURCE_DIR + "NUnitEngine/nunit-agent-x86/nunit-agent-x8
var ENGINE_API_PROJECT = SOURCE_DIR + "NUnitEngine/nunit.engine.api/nunit.engine.api.csproj";
var ENGINE_CORE_PROJECT = SOURCE_DIR + "NUnitEngine/nunit.engine.core/nunit.engine.core.csproj";
var ENGINE_TESTS_PROJECT = SOURCE_DIR + "NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj";
var ENGINE_CORE_TESTS_PROJECT = SOURCE_DIR + "NUnitEngine/nunit.engine.core.tests/nunit.engine.core.tests.csproj";
var CONSOLE_PROJECT = SOURCE_DIR + "NUnitConsole/nunit3-console/nunit3-console.csproj";
var CONSOLE_TESTS_PROJECT = SOURCE_DIR + "NUnitConsole/nunit3-console.tests/nunit3-console.tests.csproj";
var MOCK_ASSEMBLY_PROJECT = SOURCE_DIR + "NUnitEngine/mock-assembly/mock-assembly.csproj";
Expand All @@ -38,7 +39,8 @@ var NOTEST_PROJECT = SOURCE_DIR + "NUnitEngine/notest-assembly/notest-assembly.c
// Console Runner
var NET20_CONSOLE = BIN_DIR + "net20/nunit3-console.exe";
var NETCORE31_CONSOLE = BIN_DIR + "netcoreapp3.1/nunit3-console.dll";
// Unit Tests
// Test Assemblies
var ENGINE_CORE_TESTS = "nunit.engine.core.tests.dll";
var ENGINE_TESTS = "nunit.engine.tests.dll";
var CONSOLE_TESTS = "nunit3-console.tests.dll";

Expand Down
5 changes: 3 additions & 2 deletions cake/package-definitions.cake
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ public void InitializePackageDefinitions(ICakeContext context)
HasDirectory("bin/netstandard2.0").WithFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES),
HasDirectory("bin/netcoreapp2.1").WithFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES),
HasDirectory("bin/netcoreapp3.1").WithFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES),
HasDirectory("bin/net5.0").WithFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES),
//HasDirectory("bin/net5.0").WithFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES),
HasDirectory("bin/agents/net20").WithFiles(AGENT_FILES).AndFiles(AGENT_PDB_FILES),
HasDirectory("bin/agents/net40").WithFiles(AGENT_FILES).AndFiles(AGENT_PDB_FILES)
HasDirectory("bin/agents/net40").WithFiles(AGENT_FILES).AndFiles(AGENT_PDB_FILES),
HasDirectory("bin/agents/net5.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE),
},
executable: "bin/net20/nunit3-console.exe",
tests: StandardRunnerTests.Concat(new[] { NUnitProjectTest })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NUnit.Engine.Internal.Tests
[TestFixture]
public class AssemblyHelperTests
{
private static readonly string THIS_ASSEMBLY_PATH = "nunit.engine.tests.dll";
private static readonly string THIS_ASSEMBLY_PATH = "nunit.engine.core.tests.dll";

[Test]
public void GetPathForAssembly()
Expand Down
17 changes: 17 additions & 0 deletions src/NUnitEngine/nunit.engine.core.tests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

#if !NET35
using System.Reflection;
using NUnitLite;

namespace NUnit.Engine.Tests
{
class Program
{
static int Main(string[] args)
{
return new TextRunner(typeof(Program).GetTypeInfo().Assembly).Execute(args);
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ public void Initialize()
// Add all services needed by any of our TestEngineRunners
_services = new ServiceContext();
_services.Add(new Services.ExtensionService());
_services.Add(new Services.ProjectService());
#if NETFRAMEWORK
_services.Add(new Services.DomainManager());
_services.Add(new Services.RuntimeFrameworkService());
_services.Add(new Services.TestAgency());
#endif
_services.Add(new Services.DriverService());
_services.Add(new Services.DefaultTestRunnerFactory());
_services.ServiceManager.StartServices();

var mockAssemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "mock-assembly.dll");
Expand Down Expand Up @@ -115,10 +111,11 @@ public void Run()
[Test]
public void RunAsync()
{
#if NETFRAMEWORK
if (_runner is ProcessRunner || _runner is MultipleTestProcessRunner)
Assert.Ignore("RunAsync is not working for ProcessRunner");
#endif
// TODO
//#if NETFRAMEWORK
// if (_runner is ProcessRunner || _runner is MultipleTestProcessRunner)
// Assert.Ignore("RunAsync is not working for ProcessRunner");
//#endif

var asyncResult = _runner.RunAsync(null, TestFilter.Empty);
asyncResult.Wait(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class DomainManagerStaticTests
static string path2 = TestPath("/test/bin/debug/test2.dll");
static string path3 = TestPath("/test/utils/test3.dll");

const string STANDARD_CONFIG_FILE = "nunit.engine.tests.dll.config";
const string STANDARD_CONFIG_FILE = "nunit.engine.core.tests.dll.config";
const string ALTERNATE_CONFIG_FILE = "alt.config";

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public void ServiceIsStarted()
}


#if NETCOREAPP3_1_OR_GREATER
#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))]
#elif NETCOREAPP3_1
[TestCase("mock-assembly.dll", false, typeof(NUnitNetCore31Driver))]
[TestCase("mock-assembly.dll", true, typeof(NUnitNetCore31Driver))]
[TestCase("notest-assembly.dll", false, typeof(NUnitNetCore31Driver))]
Expand All @@ -49,8 +53,10 @@ public void ServiceIsStarted()
[TestCase("junk.dll", false, typeof(InvalidAssemblyFrameworkDriver))]
[TestCase("junk.dll", true, typeof(InvalidAssemblyFrameworkDriver))]
[TestCase("nunit.engine.dll", false, typeof(InvalidAssemblyFrameworkDriver))]
#if !NET5_0 // Not yet working
[TestCase("nunit.engine.dll", true, typeof(SkippedAssemblyFrameworkDriver))]
[TestCase("notest-assembly.dll", true, typeof(SkippedAssemblyFrameworkDriver))]
#endif
public void CorrectDriverIsUsed(string fileName, bool skipNonTestAssemblies, Type expectedType)
{
var driver = _driverService.GetDriver(AppDomain.CurrentDomain, Path.Combine(TestContext.CurrentContext.TestDirectory, fileName), null, skipNonTestAssemblies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void CreateService()
// Rather than actually starting the service, which would result
// in finding the extensions actually in use on the current system,
// we simulate the start using this assemblies dummy extensions.
_serviceClass.FindExtensionPoints(typeof(TestEngine).Assembly);
_serviceClass.FindExtensionPoints(typeof(CoreEngine).Assembly);
_serviceClass.FindExtensionPoints(typeof(ITestEngine).Assembly);

Expand Down Expand Up @@ -159,7 +158,7 @@ public void SkipsGracefullyLoadingOtherFrameworkExtensionAssembly()
Assert.That(assemblyName, Does.Exist);

var service = new ExtensionService();
service.FindExtensionPoints(typeof(TestEngine).Assembly);
service.FindExtensionPoints(typeof(CoreEngine).Assembly);
service.FindExtensionPoints(typeof(ITestEngine).Assembly);
var extensionAssembly = new ExtensionAssembly(assemblyName, false);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;

namespace NUnit.Engine.Services.Tests.Fakes
{
interface IFakeService
{ }

public class FakeService : IFakeService, IService
{
IServiceLocator IService.ServiceContext { get; set; }

private ServiceStatus _status;
ServiceStatus IService.Status
{
get { return _status; }
}

void IService.StartService()
{
_status = FailToStart
? ServiceStatus.Error
: ServiceStatus.Started;
}

void IService.StopService()
{
_status = ServiceStatus.Stopped;
if (FailedToStop)
throw new ArgumentException(nameof(FailedToStop));
}

public bool FailToStart { get; set; }

public bool FailedToStop { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace NUnit.Engine.Services.Tests
{
using Fakes;

public class InProcessTestRunnerFactoryTests
{
private InProcessTestRunnerFactory _factory;
Expand Down
Loading

0 comments on commit cb020f4

Please sign in to comment.