From e4bd142377c40308918a6e7f2a29c22cf38f9a60 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Tue, 17 Dec 2024 17:31:20 +0100 Subject: [PATCH] feat: Add templates for xunit.v3 --- .github/workflows/ci.yml | 8 ++++++++ CHANGELOG.md | 4 ++++ .../.template.config/dotnetcli.host.json | 1 + .../template/.template.config/template.json | 11 ++++++++++- .../template/Company.BlazorTests1.csproj | 19 ++++++++++++++----- .../template/CounterCSharpTests.cs | 6 ++++-- .../template/CounterRazorTests.razor | 6 +++--- src/bunit.template/template/_Imports.razor | 2 +- 8 files changed, 45 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e106dd43..b103dc6aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -191,6 +191,14 @@ jobs: dotnet restore ${{ github.workspace }}/TemplateTestXunit --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} dotnet test ${{ github.workspace }}/TemplateTestXunit + - name: ✔ Verify xUnit.v3 template + run: | + dotnet new bunit --framework xunitv3 --no-restore -o ${{ github.workspace }}/TemplateTestXunitv3 + echo '' >> ${{ github.workspace }}/TemplateTestXunitv3/Directory.Build.props + echo 'false' >> ${{ github.workspace }}/TemplateTestXunitv3/Directory.Packages.props + dotnet restore ${{ github.workspace }}/TemplateTestXunitv3 --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} + dotnet test ${{ github.workspace }}/TemplateTestXunitv3 + - name: ✔ Verify NUnit template run: | dotnet new bunit --framework nunit --no-restore -o ${{ github.workspace }}/TemplateTestNunit diff --git a/CHANGELOG.md b/CHANGELOG.md index 54d178487..e667047d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Added + +- Added support for xunit v3 in the bunit.template. By [@linkdotnet](https://github.com/linkdotnet). + ## [1.37.7] - 2024-12-13 ### Added diff --git a/src/bunit.template/template/.template.config/dotnetcli.host.json b/src/bunit.template/template/.template.config/dotnetcli.host.json index c8adcf8a7..ced81d900 100644 --- a/src/bunit.template/template/.template.config/dotnetcli.host.json +++ b/src/bunit.template/template/.template.config/dotnetcli.host.json @@ -15,6 +15,7 @@ }, "usageExamples": [ "--framework xunit --sdk net8.0", + "--framework xunitv3 --sdk net8.0", "--framework nunit --sdk net8.0", "--framework mstest --sdk net8.0" ] diff --git a/src/bunit.template/template/.template.config/template.json b/src/bunit.template/template/.template.config/template.json index 646e9a8ef..6f8633000 100644 --- a/src/bunit.template/template/.template.config/template.json +++ b/src/bunit.template/template/.template.config/template.json @@ -24,7 +24,7 @@ "modifiers": [ { "exclude": [ "BunitTestContext.cs" ], - "condition": "(testFramework_xunit)" + "condition": "(testFramework_xunit || testFramework_xunitv3)" } ] } @@ -58,6 +58,11 @@ "description": "xUnit unit testing framework", "displayName": "xUnit" }, + { + "choice": "xunitv3", + "description": "xUnit v3 unit testing framework", + "displayName": "xUnit v3" + }, { "choice": "mstest", "description": "MSTest unit testing framework", @@ -73,6 +78,10 @@ "type": "computed", "value": "UnitTestFramework == \"xunit\"" }, + "testFramework_xunitv3": { + "type": "computed", + "value": "UnitTestFramework == \"xunitv3\"" + }, "testFramework_mstest": { "type": "computed", "value": "UnitTestFramework == \"mstest\"" diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index 35e5fe7d5..25ce39849 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -11,14 +11,15 @@ + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -32,14 +33,22 @@ + + + + all + runtime; build; native; contentfiles; analyzers + + + - + - - + + diff --git a/src/bunit.template/template/CounterCSharpTests.cs b/src/bunit.template/template/CounterCSharpTests.cs index 020dfabbd..282271255 100644 --- a/src/bunit.template/template/CounterCSharpTests.cs +++ b/src/bunit.template/template/CounterCSharpTests.cs @@ -6,6 +6,8 @@ namespace Company.BlazorTests1; /// #if (testFramework_xunit) public class CounterCSharpTests : TestContext +#elif (testFramework_xunitv3) +public class CounterCSharpTests : Bunit.TestContext #elif (testFramework_nunit) public class CounterCSharpTests : BunitTestContext #elif (testFramework_mstest) @@ -13,7 +15,7 @@ public class CounterCSharpTests : BunitTestContext public class CounterCSharpTests : BunitTestContext #endif { -#if (testFramework_xunit) +#if (testFramework_xunit || testFramework_xunitv3) [Fact] #elif (testFramework_nunit) [Test] @@ -29,7 +31,7 @@ public void CounterStartsAtZero() cut.Find("p").MarkupMatches("

Current count: 0

"); } -#if (testFramework_xunit) +#if (testFramework_xunit || testFramework_xunitv3) [Fact] #elif (testFramework_nunit) [Test] diff --git a/src/bunit.template/template/CounterRazorTests.razor b/src/bunit.template/template/CounterRazorTests.razor index 7992eda2d..d02bafd4c 100644 --- a/src/bunit.template/template/CounterRazorTests.razor +++ b/src/bunit.template/template/CounterRazorTests.razor @@ -1,4 +1,4 @@ -@*#if (testFramework_xunit)*@ +@*#if (testFramework_xunit || testFramework_xunitv3) *@ @inherits TestContext @*#elif (testFramework_nunit)*@ @inherits BunitTestContext @@ -12,7 +12,7 @@ These tests are written entirely in razor and C# syntax. Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating-basic-tests-in-razor-files @code { -@*#if (testFramework_xunit)*@ +@*#if (testFramework_xunit || testFramework_xunitv3)*@ [Fact] @*#elif (testFramework_nunit)*@ [Test] @@ -27,7 +27,7 @@ Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating // Assert that content of the paragraph shows counter at zero cut.Find("p").MarkupMatches(@

Current count: 0

); } -@*#if (testFramework_xunit)*@ +@*#if (testFramework_xunit || testFramework_xunitv3)*@ [Fact] @*#elif (testFramework_nunit)*@ [Test] diff --git a/src/bunit.template/template/_Imports.razor b/src/bunit.template/template/_Imports.razor index 054402d02..1f90d2779 100644 --- a/src/bunit.template/template/_Imports.razor +++ b/src/bunit.template/template/_Imports.razor @@ -3,7 +3,7 @@ @using Microsoft.Extensions.DependencyInjection @using Bunit @using Bunit.TestDoubles -@*#if (testFramework_xunit)*@ +@*#if (testFramework_xunit || testFramework_xunitv3)*@ @using Xunit @*#elif (testFramework_nunit)*@ @using NUnit.Framework