Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use xunit v3 as testing framework #14

Merged
merged 6 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 3 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="aweXpect" Version="0.7.0"/>
<PackageVersion Include="aweXpect.Core" Version="0.7.0"/>
<PackageVersion Include="aweXpect" Version="0.14.1"/>
</ItemGroup>
<ItemGroup>
<PackageVersion Include="MinVer" Version="6.0.0"/>
Expand All @@ -21,12 +20,8 @@
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageVersion Include="NUnit" Version="4.2.2"/>
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0"/>
<PackageVersion Include="NUnit.Analyzers" Version="4.4.0"/>
<PackageVersion Include="xunit" Version="2.9.2"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageVersion Include="AutoFixture.Xunit2" Version="4.18.1"/>
<PackageVersion Include="xunit.v3" Version="1.0.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0"/>
<PackageVersion Include="coverlet.collector" Version="6.0.2"/>
<PackageVersion Include="PublicApiGenerator" Version="11.1.0"/>
</ItemGroup>
Expand Down
34 changes: 6 additions & 28 deletions Pipeline/Build.UnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
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 System.Linq;
using static Nuke.Common.Tools.Xunit.XunitTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

// ReSharper disable AllUnderscoreLocalParameterName
Expand All @@ -15,41 +12,22 @@ namespace Build;
partial class Build
{
Target UnitTests => _ => _
.DependsOn(DotNetFrameworkUnitTests)
.DependsOn(DotNetUnitTests);

Project[] UnitTestProjects =>
[
Solution.Tests.aweXpect_Chronology_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();

Assert.NotEmpty(testAssemblies.ToList());

Xunit2(s => s
.SetFramework("net48")
.AddTargetAssemblies(testAssemblies)
);
});

Target DotNetUnitTests => _ => _
.Unlisted()
.DependsOn(Compile)
.Executes(() =>
{
string net48 = "net48";
string[] excludedFrameworks =
EnvironmentInfo.IsWin
? []
: ["net48"];
DotNetTest(s => s
.SetConfiguration(Configuration)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
Expand All @@ -61,7 +39,7 @@ partial class Build
(settings, project) => settings
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks()?.Except([net48]),
project.GetTargetFrameworks()?.Except(excludedFrameworks),
(frameworkSettings, framework) => frameworkSettings
.SetFramework(framework)
.AddLoggers($"trx;LogFileName={project.Name}_{framework}.trx")
Expand Down
5 changes: 3 additions & 2 deletions Tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>701;1702;CA1845</NoWarn>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit"/>
<PackageReference Include="aweXpect"/>
<PackageReference Include="xunit.v3"/>
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="AutoFixture.Xunit2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="Nullable">
<PrivateAssets>all</PrivateAssets>
Expand Down
11 changes: 5 additions & 6 deletions Tests/aweXpect.Chronology.Api.Tests/ApiAcceptance.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using NUnit.Framework;
using System.Threading.Tasks;

namespace aweXpect.Api.Tests;
namespace aweXpect.Chronology.Api.Tests;

public sealed class ApiAcceptance
{
/// <summary>
/// Execute this test to update the expected public API to the current API surface.
/// </summary>
[TestCase]
[Explicit]
public void AcceptApiChanges()
[Fact(Explicit = true)]
public async Task AcceptApiChanges()
{
string[] assemblyNames =
[
Expand All @@ -27,6 +26,6 @@ public void AcceptApiChanges()
}
}

Assert.That(assemblyNames, Is.Not.Empty);
await Expect.That(assemblyNames).Should().NotBeEmpty();
}
}
30 changes: 9 additions & 21 deletions Tests/aweXpect.Chronology.Api.Tests/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections;
using NUnit.Framework;
using System.Threading.Tasks;

namespace aweXpect.Api.Tests;
namespace aweXpect.Chronology.Api.Tests;

/// <summary>
/// Whenever a test fails, this means that the public API surface changed.
Expand All @@ -10,29 +9,18 @@ namespace aweXpect.Api.Tests;
/// </summary>
public sealed class ApiApprovalTests
{
[TestCaseSource(typeof(TargetFrameworksTheoryData))]
public void VerifyPublicApiForAweXpectChronology(string framework)
public static TheoryData<string> TargetFrameworksTheoryData
=> new(Helper.GetTargetFrameworks());

[Theory]
[MemberData(nameof(TargetFrameworksTheoryData))]
public async Task VerifyPublicApiForAweXpectChronology(string framework)
{
const string assemblyName = "aweXpect.Chronology";

string publicApi = Helper.CreatePublicApi(framework, assemblyName);
string expectedApi = Helper.GetExpectedApi(framework, assemblyName);

Assert.That(publicApi, Is.EqualTo(expectedApi));
}

private sealed class TargetFrameworksTheoryData : IEnumerable
{
#region IEnumerable Members

public IEnumerator GetEnumerator()
{
foreach (string targetFramework in Helper.GetTargetFrameworks())
{
yield return new object[] { targetFramework };
}
}

#endregion
await Expect.That(publicApi).Should().Be(expectedApi);
}
}
2 changes: 1 addition & 1 deletion Tests/aweXpect.Chronology.Api.Tests/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Xml.XPath;
using PublicApiGenerator;

namespace aweXpect.Api.Tests;
namespace aweXpect.Chronology.Api.Tests;

public static class Helper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Remove="xunit"/>
<PackageReference Remove="xunit.runner.visualstudio"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit.Analyzers"/>
<PackageReference Include="NUnit3TestAdapter"/>
<PackageReference Include="PublicApiGenerator"/>
</ItemGroup>

Expand Down
14 changes: 8 additions & 6 deletions Tests/aweXpect.Chronology.Tests/TimeSpanExtensions.DaysTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public sealed partial class TimeSpanExtensions
public sealed class DaysTests
{
[Theory]
[AutoData]
[InlineData(1.2)]
public async Task Days_Double_ShouldReturnCorrectTimeSpan(double days)
{
TimeSpan expected = TimeSpan.FromDays(days);
Expand All @@ -16,10 +16,11 @@ public async Task Days_Double_ShouldReturnCorrectTimeSpan(double days)
}

[Theory]
[AutoData]
[InlineData(1.2, 3.4)]
public async Task Days_Double_WithOffset_ShouldReturnCorrectTimeSpan(double days,
TimeSpan offset)
double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = TimeSpan.FromDays(days) + offset;

TimeSpan result = days.Days(offset);
Expand All @@ -28,7 +29,7 @@ public async Task Days_Double_WithOffset_ShouldReturnCorrectTimeSpan(double days
}

[Theory]
[AutoData]
[InlineData(1)]
public async Task Days_Int_ShouldReturnCorrectTimeSpan(int days)
{
TimeSpan expected = days.Days();
Expand All @@ -39,9 +40,10 @@ public async Task Days_Int_ShouldReturnCorrectTimeSpan(int days)
}

[Theory]
[AutoData]
public async Task Days_Int_WithOffset_ShouldReturnCorrectTimeSpan(int days, TimeSpan offset)
[InlineData(1, 3.4)]
public async Task Days_Int_WithOffset_ShouldReturnCorrectTimeSpan(int days, double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = days.Days() + offset;

TimeSpan result = days.Days(offset);
Expand Down
14 changes: 8 additions & 6 deletions Tests/aweXpect.Chronology.Tests/TimeSpanExtensions.HoursTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public sealed partial class TimeSpanExtensions
public sealed class HoursTests
{
[Theory]
[AutoData]
[InlineData(1.2)]
public async Task Hours_Double_ShouldReturnCorrectTimeSpan(double hours)
{
TimeSpan expected = TimeSpan.FromHours(hours);
Expand All @@ -16,10 +16,11 @@ public async Task Hours_Double_ShouldReturnCorrectTimeSpan(double hours)
}

[Theory]
[AutoData]
[InlineData(1.2, 3.4)]
public async Task Hours_Double_WithOffset_ShouldReturnCorrectTimeSpan(double hours,
TimeSpan offset)
double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = TimeSpan.FromHours(hours) + offset;

TimeSpan result = hours.Hours(offset);
Expand All @@ -28,7 +29,7 @@ public async Task Hours_Double_WithOffset_ShouldReturnCorrectTimeSpan(double hou
}

[Theory]
[AutoData]
[InlineData(1)]
public async Task Hours_Int_ShouldReturnCorrectTimeSpan(int hours)
{
TimeSpan expected = TimeSpan.FromHours(hours);
Expand All @@ -39,9 +40,10 @@ public async Task Hours_Int_ShouldReturnCorrectTimeSpan(int hours)
}

[Theory]
[AutoData]
public async Task Hours_Int_WithOffset_ShouldReturnCorrectTimeSpan(int hours, TimeSpan offset)
[InlineData(1, 3.4)]
public async Task Hours_Int_WithOffset_ShouldReturnCorrectTimeSpan(int hours, double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = TimeSpan.FromHours(hours) + offset;

TimeSpan result = hours.Hours(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public sealed partial class TimeSpanExtensions
public sealed class MillisecondsTests
{
[Theory]
[AutoData]
[InlineData(1.2)]
public async Task Milliseconds_Double_ShouldReturnCorrectTimeSpan(double milliseconds)
{
TimeSpan expected = TimeSpan.FromMilliseconds(milliseconds);
Expand All @@ -16,10 +16,11 @@ public async Task Milliseconds_Double_ShouldReturnCorrectTimeSpan(double millise
}

[Theory]
[AutoData]
[InlineData(1.2, 3.4)]
public async Task Milliseconds_Double_WithOffset_ShouldReturnCorrectTimeSpan(
double milliseconds, TimeSpan offset)
double milliseconds, double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = TimeSpan.FromMilliseconds(milliseconds) + offset;

TimeSpan result = milliseconds.Milliseconds(offset);
Expand All @@ -28,7 +29,7 @@ public async Task Milliseconds_Double_WithOffset_ShouldReturnCorrectTimeSpan(
}

[Theory]
[AutoData]
[InlineData(1)]
public async Task Milliseconds_Int_ShouldReturnCorrectTimeSpan(int milliseconds)
{
TimeSpan expected = TimeSpan.FromMilliseconds(milliseconds);
Expand All @@ -39,10 +40,11 @@ public async Task Milliseconds_Int_ShouldReturnCorrectTimeSpan(int milliseconds)
}

[Theory]
[AutoData]
[InlineData(1, 3.4)]
public async Task Milliseconds_Int_WithOffset_ShouldReturnCorrectTimeSpan(int milliseconds,
TimeSpan offset)
double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = TimeSpan.FromMilliseconds(milliseconds) + offset;

TimeSpan result = milliseconds.Milliseconds(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public sealed partial class TimeSpanExtensions
public sealed class MinutesTests
{
[Theory]
[AutoData]
[InlineData(1.2)]
public async Task Minutes_Double_ShouldReturnCorrectTimeSpan(double minutes)
{
TimeSpan expected = TimeSpan.FromMinutes(minutes);
Expand All @@ -16,10 +16,11 @@ public async Task Minutes_Double_ShouldReturnCorrectTimeSpan(double minutes)
}

[Theory]
[AutoData]
[InlineData(1.2, 3.4)]
public async Task Minutes_Double_WithOffset_ShouldReturnCorrectTimeSpan(double minutes,
TimeSpan offset)
double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = TimeSpan.FromMinutes(minutes) + offset;

TimeSpan result = minutes.Minutes(offset);
Expand All @@ -28,7 +29,7 @@ public async Task Minutes_Double_WithOffset_ShouldReturnCorrectTimeSpan(double m
}

[Theory]
[AutoData]
[InlineData(1)]
public async Task Minutes_Int_ShouldReturnCorrectTimeSpan(int minutes)
{
TimeSpan expected = TimeSpan.FromMinutes(minutes);
Expand All @@ -39,10 +40,11 @@ public async Task Minutes_Int_ShouldReturnCorrectTimeSpan(int minutes)
}

[Theory]
[AutoData]
[InlineData(1, 3.4)]
public async Task Minutes_Int_WithOffset_ShouldReturnCorrectTimeSpan(int minutes,
TimeSpan offset)
double offsetSeconds)
{
TimeSpan offset = TimeSpan.FromSeconds(offsetSeconds);
TimeSpan expected = TimeSpan.FromMinutes(minutes) + offset;

TimeSpan result = minutes.Minutes(offset);
Expand Down
Loading
Loading