Skip to content

Commit

Permalink
Merge pull request #4315 from nunit/stepbystep
Browse files Browse the repository at this point in the history
Stepbystep fixing debugging and testing NUnit in Visual Studio
  • Loading branch information
OsirisTerje committed Mar 25, 2023
2 parents 03dd6c2 + c1b5dba commit ce3b2ce
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
70 changes: 49 additions & 21 deletions build.cake
Expand Up @@ -51,6 +51,11 @@ var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var PACKAGE_DIR = Argument("artifact-dir", PROJECT_DIR + "package") + "/";
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
var IMAGE_DIR = PROJECT_DIR + "images/";
var NUNITFRAMWORKTESTSBIN = PROJECT_DIR + "src/NUnitFramework/tests/bin/" + configuration + "/";
var NUNITLITETESTSBIN = PROJECT_DIR + "src/NUnitFramework/nunitlite.tests/bin/" + configuration + "/";
var NUNITFRAMEWORKBIN = PROJECT_DIR + "src/NUnitFramework/framework/bin/" + configuration + "/";
var NUNITLITEBIN = PROJECT_DIR + "src/NUnitFramework/nunitlite/bin/" + configuration + "/";
var NUNITLITERUNNERBIN = PROJECT_DIR + "src/NUnitFramework/nunitlite-runner/bin/" + configuration + "/";

var SOLUTION_FILE = "./nunit.sln";

Expand Down Expand Up @@ -120,10 +125,12 @@ Setup(context =>
//////////////////////////////////////////////////////////////////////

Task("Clean")
.Description("Deletes all files in the BIN directory")
.Description("Deletes all files in the BIN directories")
.Does(() =>
{
CleanDirectory(BIN_DIR);
CleanDirectory(NUNITFRAMEWORKBIN);
CleanDirectory(NUNITLITEBIN);
CleanDirectory(NUNITLITERUNNERBIN);
});

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -172,9 +179,12 @@ Task("TestNetFramework")
.Does(() =>
{
var runtime = "net462";
var dir = BIN_DIR + runtime + "/";
var dir = NUNITFRAMWORKTESTSBIN + runtime + "/";
Information("Run tests for " + runtime + " in " + dir+"using runner");
RunTest(dir + EXECUTABLE_NUNITLITE_TEST_RUNNER_EXE, dir, FRAMEWORK_TESTS, dir + "nunit.framework.tests.xml", runtime, ref ErrorDetail);
//RunNUnitTests(dir, FRAMEWORK_TESTS, runtime, ref ErrorDetail);
dir = NUNITLITETESTSBIN + runtime + "/";
Information("Run tests for " + runtime + " in " + dir+" for nunitlite.tests");
RunTest(dir + EXECUTABLE_NUNITLITE_TESTS_EXE, dir, runtime, ref ErrorDetail);
PublishTestResults(runtime);
});
Expand All @@ -191,8 +201,11 @@ foreach (var runtime in NetCoreTests)
.OnError(exception => { ErrorDetail.Add(exception.Message); })
.Does(() =>
{
var dir = BIN_DIR + runtime + "/";
var dir = NUNITFRAMWORKTESTSBIN + runtime + "/";
Information("Run tests for " + runtime + " in " + dir);
RunDotnetCoreTests(dir + NUNITLITE_RUNNER_DLL, dir, FRAMEWORK_TESTS, runtime, GetResultXmlPath(FRAMEWORK_TESTS, runtime), ref ErrorDetail);
dir = NUNITLITETESTSBIN + runtime + "/";
Information("Run tests for " + runtime + " in " + dir+" for nunitlite.tests");
RunDotnetCoreTests(dir + EXECUTABLE_NUNITLITE_TESTS_DLL, dir, runtime, ref ErrorDetail);
PublishTestResults(runtime);
});
Expand Down Expand Up @@ -252,30 +265,41 @@ Task("CreateImage")
var imageBinDir = CurrentImageDir + "bin/";
CreateDirectory(imageBinDir);
Information("Created directory " + imageBinDir);
foreach (var runtime in LibraryFrameworks)
Information("Created imagedirectory at:" + imageBinDir);
var directories = new String[]
{
NUNITFRAMEWORKBIN,
NUNITLITEBIN
};
foreach (var dir in directories)
{
var targetDir = imageBinDir + Directory(runtime);
var sourceDir = BIN_DIR + Directory(runtime);
CreateDirectory(targetDir);
foreach (FilePath file in FrameworkFiles)
foreach (var runtime in LibraryFrameworks)
{
var sourcePath = sourceDir + "/" + file;
if (FileExists(sourcePath))
CopyFileToDirectory(sourcePath, targetDir);
var targetDir = imageBinDir + Directory(runtime);
var sourceDir = dir + Directory(runtime);
CreateDirectory(targetDir);
Information("Created directory " + targetDir);
foreach (FilePath file in FrameworkFiles)
{
var sourcePath = sourceDir + "/" + file;
if (FileExists(sourcePath))
CopyFileToDirectory(sourcePath, targetDir);
}
Information("Files copied from " + sourceDir + " to " + targetDir);
var schemaPath = sourceDir + "/Schemas";
if (DirectoryExists(schemaPath))
CopyDirectory(sourceDir, targetDir);
}
var schemaPath = sourceDir + "/Schemas";
if (DirectoryExists(schemaPath))
CopyDirectory(sourceDir, targetDir);
}
}
foreach (var dir in NetCoreTests)
{
var targetDir = imageBinDir + Directory(dir);
var sourceDir = BIN_DIR + Directory(dir);
var sourceDir = NUNITLITERUNNERBIN + Directory(dir);
Information("Copying " + sourceDir + " to " + targetDir);
CopyDirectory(sourceDir, targetDir);
}
}
CopyDirectory(NUNITLITERUNNERBIN + Directory("net462"),imageBinDir+Directory("net462"));
});

Task("PackageFramework")
Expand Down Expand Up @@ -468,7 +492,10 @@ void RunDotnetCoreTests(FilePath exePath, DirectoryPath workingDir, string frame
void RunDotnetCoreTests(FilePath exePath, DirectoryPath workingDir, string arguments, string framework, FilePath resultFile, ref List<string> errorDetail)
{
if (!FileExists(exePath))
{
Information(string.Format("{0}: {1} not found", framework, exePath));
return;
}

int rc = StartProcess(
"dotnet",
Expand All @@ -492,6 +519,7 @@ void PublishTestResults(string framework)
{
if (EnvironmentVariable("TF_BUILD", false))
{
Information("Publishing test results to Azure Pipelines");
var fullTestRunTitle = framework;
var ciRunName = Argument<string>("test-run-name");
if (!string.IsNullOrEmpty(ciRunName))
Expand Down
7 changes: 4 additions & 3 deletions nunit.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30709.132
# Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.framework", "src\NUnitFramework\framework\nunit.framework.csproj", "{B7753E96-F76B-4E9B-9071-47B16DB90FD6}"
EndProject
Expand Down Expand Up @@ -44,6 +44,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "framework", "framework", "{CE68713C-2E19-43E8-9333-6ED817110D52}"
ProjectSection(SolutionItems) = preProject
nuget\framework\nunit.nuspec = nuget\framework\nunit.nuspec
nuget\framework\NUnit.props = nuget\framework\NUnit.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nunitlite", "nunitlite", "{8D43A220-7FE8-4214-BBB4-08568B88C7AA}"
Expand All @@ -53,7 +54,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nunitlite", "nunitlite", "{
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "nunit.testdata.fsharp", "src\NUnitFramework\testdata.fsharp\nunit.testdata.fsharp.fsproj", "{9DF6B262-70E2-44E3-A436-3B65C7FD88DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.framework.benchmarks", "src\NUnitFramework\benchmarks\nunit.framework.benchmarks\nunit.framework.benchmarks.csproj", "{D0D08E09-8FF4-487D-AE61-C9CCCCA8CBB0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.framework.benchmarks", "src\NUnitFramework\benchmarks\nunit.framework.benchmarks\nunit.framework.benchmarks.csproj", "{D0D08E09-8FF4-487D-AE61-C9CCCCA8CBB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitFramework/Directory.Build.props
Expand Up @@ -9,7 +9,7 @@
<NUnitLibraryFrameworks>net462;netstandard2.0</NUnitLibraryFrameworks>
<NUnitRuntimeFrameworks>net462;netcoreapp3.1;net5.0;net6.0;net7.0</NUnitRuntimeFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputPath>..\..\..\bin\$(Configuration)\</OutputPath>
<!--<OutputPath>..\..\..\bin\$(Configuration)\</OutputPath>-->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

Expand Down
5 changes: 4 additions & 1 deletion src/NUnitFramework/framework/Internal/AssemblyHelper.cs
Expand Up @@ -3,6 +3,9 @@
using System;
using System.IO;
using System.Reflection;
#if NETSTANDARD2_0
using System.Runtime.Loader;
#endif

namespace NUnit.Framework.Internal
{
Expand Down Expand Up @@ -101,7 +104,7 @@ private static ReflectionAssemblyLoader TryInitialize()
.CreateDelegate(typeof(Func<string, Assembly>), defaultContext);

assemblyLoadContextType.GetRuntimeEvent("Resolving").AddEventHandler(defaultContext,
new Func<object, AssemblyName, Assembly>((context, assemblyName) =>
new Func<AssemblyLoadContext, AssemblyName, Assembly>((context, assemblyName) =>
{
var dllPath = Path.Combine(AppContext.BaseDirectory, assemblyName.Name + ".dll");
if (File.Exists(dllPath)) return loadFromAssemblyPath.Invoke(dllPath);
Expand Down
1 change: 1 addition & 0 deletions src/NUnitFramework/framework/nunit.framework.csproj
Expand Up @@ -14,6 +14,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitFramework/testdata/nunit.testdata.csproj
Expand Up @@ -17,8 +17,8 @@
<ProjectReference Include="..\framework\nunit.framework.csproj" />
</ItemGroup>

<ItemGroup>
<!--<ItemGroup>
<ProjectCapability Include="TestContainer" />
</ItemGroup>
</ItemGroup>-->

</Project>
5 changes: 3 additions & 2 deletions src/NUnitFramework/tests/nunit.framework.tests.csproj
Expand Up @@ -11,8 +11,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0-alpha.4" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="System.ValueTuple" version="4.5.0" />
</ItemGroup>
Expand All @@ -23,6 +23,7 @@
<ProjectReference Include="..\testdata\nunit.testdata.csproj" />
<ProjectReference Include="..\mock-assembly\mock-assembly.csproj" />
<ProjectReference Include="..\testdata.fsharp\nunit.testdata.fsharp.fsproj" />
<ProjectReference Include="..\nunitlite-runner\nunitlite-runner.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
Expand Down

0 comments on commit ce3b2ce

Please sign in to comment.