Skip to content

Commit 1504e5f

Browse files
committed
Use NUnit in pipeline
1 parent 573e392 commit 1504e5f

File tree

3 files changed

+72
-65
lines changed

3 files changed

+72
-65
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)StrongName.snk</AssemblyOriginatorKeyFile>
99
<LangVersion>latest</LangVersion>
1010
<PackageTags>testing</PackageTags>
11+
<NoWarn>CS1591</NoWarn>
1112
<PackageProjectUrl>https://github.com/TestableIO/System.IO.Abstractions</PackageProjectUrl>
1213
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1314
<PackageReadmeFile>README.md</PackageReadmeFile>

Pipeline/Build.UnitTest.cs

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
using System.IO;
12
using System.Linq;
23
using Nuke.Common;
34
using Nuke.Common.IO;
45
using Nuke.Common.ProjectModel;
56
using Nuke.Common.Tooling;
67
using Nuke.Common.Tools.DotNet;
7-
using Nuke.Common.Tools.Xunit;
8-
using static Nuke.Common.Tools.Xunit.XunitTasks;
8+
using Nuke.Common.Tools.NUnit;
99
using static Nuke.Common.Tools.DotNet.DotNetTasks;
1010

1111
// ReSharper disable AllUnderscoreLocalParameterName
@@ -14,61 +14,66 @@ namespace Build;
1414

1515
partial class Build
1616
{
17-
Target UnitTests => _ => _
18-
.DependsOn(DotNetFrameworkUnitTests)
19-
.DependsOn(DotNetUnitTests);
17+
Target UnitTests => _ => _
18+
.DependsOn(DotNetFrameworkUnitTests)
19+
.DependsOn(DotNetUnitTests);
2020

21-
Project[] UnitTestProjects =>
22-
[
23-
Solution.Tests.TestableIO_System_IO_Abstractions_Wrappers_Tests,
24-
Solution.Tests.TestableIO_System_IO_Abstractions_TestingHelpers_Tests,
25-
Solution.Tests.TestableIO_System_IO_Abstractions_Parity_Tests,
26-
];
21+
Project[] UnitTestProjects =>
22+
[
23+
Solution.Tests.TestableIO_System_IO_Abstractions_Wrappers_Tests,
24+
Solution.Tests.TestableIO_System_IO_Abstractions_TestingHelpers_Tests,
25+
Solution.Tests.TestableIO_System_IO_Abstractions_Parity_Tests,
26+
];
2727

28-
Target DotNetFrameworkUnitTests => _ => _
29-
.Unlisted()
30-
.DependsOn(Compile)
31-
.OnlyWhenDynamic(() => EnvironmentInfo.IsWin)
32-
.Executes(() =>
33-
{
34-
string[] testAssemblies = UnitTestProjects
35-
.SelectMany(project =>
36-
project.Directory.GlobFiles(
37-
$"bin/{(Configuration == Configuration.Debug ? "Debug" : "Release")}/net48/*.Tests.dll"))
38-
.Select(p => p.ToString())
39-
.ToArray();
28+
Target DotNetFrameworkUnitTests => _ => _
29+
.Unlisted()
30+
.DependsOn(Compile)
31+
.OnlyWhenDynamic(() => EnvironmentInfo.IsWin)
32+
.Executes(() =>
33+
{
34+
var testAssemblies = UnitTestProjects
35+
.SelectMany(project =>
36+
project.Directory.GlobFiles(
37+
$"bin/{(Configuration == Configuration.Debug ? "Debug" : "Release")}/net472/*.Tests.dll"))
38+
.Select(p => p.ToString())
39+
.ToArray();
4040

41-
Assert.NotEmpty(testAssemblies.ToList());
41+
Assert.NotEmpty(testAssemblies.ToList());
42+
43+
foreach (var testAssembly in testAssemblies)
44+
{
45+
var currentDirectory = Path.GetDirectoryName(testAssembly);
4246

43-
Xunit2(s => s
44-
.SetFramework("net48")
45-
.AddTargetAssemblies(testAssemblies)
46-
);
47-
});
47+
NUnitTasks.NUnit3(s => s
48+
.SetInputFiles(testAssemblies)
49+
.SetProcessWorkingDirectory(currentDirectory)
50+
);
51+
}
52+
});
4853

49-
Target DotNetUnitTests => _ => _
50-
.Unlisted()
51-
.DependsOn(Compile)
52-
.Executes(() =>
53-
{
54-
string[] excludedFrameworks = ["net48",];
55-
DotNetTest(s => s
56-
.SetConfiguration(Configuration)
57-
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
58-
.EnableNoBuild()
59-
.SetDataCollector("XPlat Code Coverage")
60-
.SetResultsDirectory(TestResultsDirectory)
61-
.CombineWith(
62-
UnitTestProjects,
63-
(settings, project) => settings
64-
.SetProjectFile(project)
65-
.CombineWith(
66-
project.GetTargetFrameworks()?.Except(excludedFrameworks),
67-
(frameworkSettings, framework) => frameworkSettings
68-
.SetFramework(framework)
69-
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
70-
)
71-
), completeOnFailure: true
72-
);
73-
});
74-
}
54+
Target DotNetUnitTests => _ => _
55+
.Unlisted()
56+
.DependsOn(Compile)
57+
.Executes(() =>
58+
{
59+
string[] excludedFrameworks = ["net48",];
60+
DotNetTest(s => s
61+
.SetConfiguration(Configuration)
62+
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
63+
.EnableNoBuild()
64+
.SetDataCollector("XPlat Code Coverage")
65+
.SetResultsDirectory(TestResultsDirectory)
66+
.CombineWith(
67+
UnitTestProjects,
68+
(settings, project) => settings
69+
.SetProjectFile(project)
70+
.CombineWith(
71+
project.GetTargetFrameworks()?.Except(excludedFrameworks),
72+
(frameworkSettings, framework) => frameworkSettings
73+
.SetFramework(framework)
74+
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
75+
)
76+
), completeOnFailure: true
77+
);
78+
});
79+
}

Pipeline/Build.csproj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="LibGit2Sharp"/>
16-
<PackageReference Include="Nuke.Common"/>
17-
<PackageReference Include="Nuke.Components"/>
18-
<PackageReference Include="SharpCompress"/>
15+
<PackageReference Include="LibGit2Sharp" />
16+
<PackageReference Include="Nuke.Common" />
17+
<PackageReference Include="Nuke.Components" />
18+
<PackageReference Include="SharpCompress" />
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<PackageDownload Include="coverlet.console" Version="[3.1.2]"/>
23-
<PackageDownload Include="dotnet-sonarscanner" Version="[9.0.2]"/>
24-
<PackageDownload Include="dotnet-stryker" Version="[4.4.1]"/>
25-
<PackageDownload Include="GitVersion.Tool" Version="[6.0.5]"/>
26-
<PackageDownload Include="ReportGenerator" Version="[5.4.1]"/>
27-
<PackageDownload Include="xunit.runner.console" Version="[2.9.2]"/>
22+
<PackageDownload Include="coverlet.console" Version="[3.1.2]" />
23+
<PackageDownload Include="dotnet-sonarscanner" Version="[9.0.2]" />
24+
<PackageDownload Include="dotnet-stryker" Version="[4.4.1]" />
25+
<PackageDownload Include="GitVersion.Tool" Version="[6.0.5]" />
26+
<PackageDownload Include="NUnit.ConsoleRunner" Version="[3.19.2]" />
27+
<PackageDownload Include="ReportGenerator" Version="[5.4.1]" />
28+
<PackageDownload Include="xunit.runner.console" Version="[2.9.2]" />
2829
</ItemGroup>
2930

3031
</Project>

0 commit comments

Comments
 (0)