Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use NUnit in pipeline
  • Loading branch information
vbreuss committed Feb 22, 2025
commit 1504e5fccaf6d9afd2a8df58277230ae0072bf57
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)StrongName.snk</AssemblyOriginatorKeyFile>
<LangVersion>latest</LangVersion>
<PackageTags>testing</PackageTags>
<NoWarn>CS1591</NoWarn>
<PackageProjectUrl>https://github.com/TestableIO/System.IO.Abstractions</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
115 changes: 60 additions & 55 deletions Pipeline/Build.UnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.IO;
using System.Linq;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.Xunit;
using static Nuke.Common.Tools.Xunit.XunitTasks;
using Nuke.Common.Tools.NUnit;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

// ReSharper disable AllUnderscoreLocalParameterName
Expand All @@ -14,61 +14,66 @@ namespace Build;

partial class Build
{
Target UnitTests => _ => _
.DependsOn(DotNetFrameworkUnitTests)
.DependsOn(DotNetUnitTests);
Target UnitTests => _ => _
.DependsOn(DotNetFrameworkUnitTests)
.DependsOn(DotNetUnitTests);

Project[] UnitTestProjects =>
[
Solution.Tests.TestableIO_System_IO_Abstractions_Wrappers_Tests,
Solution.Tests.TestableIO_System_IO_Abstractions_TestingHelpers_Tests,
Solution.Tests.TestableIO_System_IO_Abstractions_Parity_Tests,
];
Project[] UnitTestProjects =>
[
Solution.Tests.TestableIO_System_IO_Abstractions_Wrappers_Tests,
Solution.Tests.TestableIO_System_IO_Abstractions_TestingHelpers_Tests,
Solution.Tests.TestableIO_System_IO_Abstractions_Parity_Tests,
];

Target DotNetFrameworkUnitTests => _ => _
.Unlisted()
.DependsOn(Compile)
.OnlyWhenDynamic(() => EnvironmentInfo.IsWin)
.Executes(() =>
{
string[] testAssemblies = UnitTestProjects
.SelectMany(project =>
project.Directory.GlobFiles(
$"bin/{(Configuration == Configuration.Debug ? "Debug" : "Release")}/net48/*.Tests.dll"))
.Select(p => p.ToString())
.ToArray();
Target DotNetFrameworkUnitTests => _ => _
.Unlisted()
.DependsOn(Compile)
.OnlyWhenDynamic(() => EnvironmentInfo.IsWin)
.Executes(() =>
{
var testAssemblies = UnitTestProjects
.SelectMany(project =>
project.Directory.GlobFiles(
$"bin/{(Configuration == Configuration.Debug ? "Debug" : "Release")}/net472/*.Tests.dll"))
.Select(p => p.ToString())
.ToArray();

Assert.NotEmpty(testAssemblies.ToList());
Assert.NotEmpty(testAssemblies.ToList());

foreach (var testAssembly in testAssemblies)
{
var currentDirectory = Path.GetDirectoryName(testAssembly);

Xunit2(s => s
.SetFramework("net48")
.AddTargetAssemblies(testAssemblies)
);
});
NUnitTasks.NUnit3(s => s
.SetInputFiles(testAssemblies)
.SetProcessWorkingDirectory(currentDirectory)
);
}
});

Target DotNetUnitTests => _ => _
.Unlisted()
.DependsOn(Compile)
.Executes(() =>
{
string[] excludedFrameworks = ["net48",];
DotNetTest(s => s
.SetConfiguration(Configuration)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
.EnableNoBuild()
.SetDataCollector("XPlat Code Coverage")
.SetResultsDirectory(TestResultsDirectory)
.CombineWith(
UnitTestProjects,
(settings, project) => settings
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks()?.Except(excludedFrameworks),
(frameworkSettings, framework) => frameworkSettings
.SetFramework(framework)
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
)
), completeOnFailure: true
);
});
}
Target DotNetUnitTests => _ => _
.Unlisted()
.DependsOn(Compile)
.Executes(() =>
{
string[] excludedFrameworks = ["net48",];
DotNetTest(s => s
.SetConfiguration(Configuration)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
.EnableNoBuild()
.SetDataCollector("XPlat Code Coverage")
.SetResultsDirectory(TestResultsDirectory)
.CombineWith(
UnitTestProjects,
(settings, project) => settings
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks()?.Except(excludedFrameworks),
(frameworkSettings, framework) => frameworkSettings
.SetFramework(framework)
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
)
), completeOnFailure: true
);
});
}
21 changes: 11 additions & 10 deletions Pipeline/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp"/>
<PackageReference Include="Nuke.Common"/>
<PackageReference Include="Nuke.Components"/>
<PackageReference Include="SharpCompress"/>
<PackageReference Include="LibGit2Sharp" />
<PackageReference Include="Nuke.Common" />
<PackageReference Include="Nuke.Components" />
<PackageReference Include="SharpCompress" />
</ItemGroup>

<ItemGroup>
<PackageDownload Include="coverlet.console" Version="[3.1.2]"/>
<PackageDownload Include="dotnet-sonarscanner" Version="[9.0.2]"/>
<PackageDownload Include="dotnet-stryker" Version="[4.4.1]"/>
<PackageDownload Include="GitVersion.Tool" Version="[6.0.5]"/>
<PackageDownload Include="ReportGenerator" Version="[5.4.1]"/>
<PackageDownload Include="xunit.runner.console" Version="[2.9.2]"/>
<PackageDownload Include="coverlet.console" Version="[3.1.2]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[9.0.2]" />
<PackageDownload Include="dotnet-stryker" Version="[4.4.1]" />
<PackageDownload Include="GitVersion.Tool" Version="[6.0.5]" />
<PackageDownload Include="NUnit.ConsoleRunner" Version="[3.19.2]" />
<PackageDownload Include="ReportGenerator" Version="[5.4.1]" />
<PackageDownload Include="xunit.runner.console" Version="[2.9.2]" />
</ItemGroup>

</Project>
Loading