From 9f2586688eb3c2fa787a204897fc0fd118640998 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 13 Dec 2024 16:03:23 +0000 Subject: [PATCH 1/7] Set version to '1.38-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 4b460b45b..2983632ed 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.37-preview", + "version": "1.38-preview", "assemblyVersion": { "precision": "revision" }, From f6d77e260ebd1cad9889c987565abcffdb25770a Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Tue, 17 Dec 2024 17:31:20 +0100 Subject: [PATCH 2/7] 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 | 21 +++++++++---------- .../template/Company.BlazorTests1.csproj | 19 ++++++++++++----- .../template/CounterCSharpTests.cs | 6 ++++++ .../template/CounterRazorTests.razor | 8 ++++++- src/bunit.template/template/_Imports.razor | 2 ++ 8 files changed, 52 insertions(+), 17 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..81e3820c6 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\"" @@ -85,16 +94,6 @@ "defaultValue": "net9.0", "replaces": "targetSdk", "choices": [ - { - "choice": "net6.0", - "description": ".net 6.0", - "displayName": ".net 6.0" - }, - { - "choice": "net7.0", - "description": ".net 7.0", - "displayName": ".net 7.0" - }, { "choice": "net8.0", "description": ".net 8.0", diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index 35e5fe7d5..5cf40a48c 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..254157b13 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) @@ -15,6 +17,8 @@ public class CounterCSharpTests : BunitTestContext { #if (testFramework_xunit) [Fact] +#elif (testFramework_xunitv3) + [Fact] #elif (testFramework_nunit) [Test] #elif (testFramework_mstest) @@ -31,6 +35,8 @@ public void CounterStartsAtZero() #if (testFramework_xunit) [Fact] +#elif (testFramework_xunitv3) + [Fact] #elif (testFramework_nunit) [Test] #elif (testFramework_mstest) diff --git a/src/bunit.template/template/CounterRazorTests.razor b/src/bunit.template/template/CounterRazorTests.razor index 7992eda2d..f74a8a4a1 100644 --- a/src/bunit.template/template/CounterRazorTests.razor +++ b/src/bunit.template/template/CounterRazorTests.razor @@ -1,5 +1,7 @@ -@*#if (testFramework_xunit)*@ +@*#if (testFramework_xunit) *@ @inherits TestContext +@*#elif (testFramework_xunitv3)*@ +@inherits Bunit.TestContext @*#elif (testFramework_nunit)*@ @inherits BunitTestContext @*#elif (testFramework_mstest)*@ @@ -14,6 +16,8 @@ Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating @code { @*#if (testFramework_xunit)*@ [Fact] +@*#elif (testFramework_xunitv3)*@ + [Fact] @*#elif (testFramework_nunit)*@ [Test] @*#elif (testFramework_mstest)*@ @@ -29,6 +33,8 @@ Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating } @*#if (testFramework_xunit)*@ [Fact] +@*#elif (testFramework_xunitv3)*@ + [Fact] @*#elif (testFramework_nunit)*@ [Test] @*#elif (testFramework_mstest)*@ diff --git a/src/bunit.template/template/_Imports.razor b/src/bunit.template/template/_Imports.razor index 054402d02..e49ef971e 100644 --- a/src/bunit.template/template/_Imports.razor +++ b/src/bunit.template/template/_Imports.razor @@ -5,6 +5,8 @@ @using Bunit.TestDoubles @*#if (testFramework_xunit)*@ @using Xunit +@*#elif (testFramework_xunitv3)*@ +@using Xunit @*#elif (testFramework_nunit)*@ @using NUnit.Framework @*#elif (testFramework_mstest)*@ From bcc74697e44ea813954754a0b4bea15b89708689 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 3 Jan 2025 14:54:21 +0100 Subject: [PATCH 3/7] chore: Upgrade description and template package versions --- Directory.Packages.props | 2 +- src/bunit.template/template/Company.BlazorTests1.csproj | 6 +++--- src/bunit.template/template/CounterCSharpTests.cs | 1 + src/bunit.template/template/CounterRazorTests.razor | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 48d1d7ddb..976600a38 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -131,7 +131,7 @@ - + diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index 5cf40a48c..46699f241 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -19,7 +19,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -27,7 +27,7 @@ - + all runtime; build; native; contentfiles; analyzers @@ -42,7 +42,7 @@ - + diff --git a/src/bunit.template/template/CounterCSharpTests.cs b/src/bunit.template/template/CounterCSharpTests.cs index 254157b13..359fc45c4 100644 --- a/src/bunit.template/template/CounterCSharpTests.cs +++ b/src/bunit.template/template/CounterCSharpTests.cs @@ -7,6 +7,7 @@ namespace Company.BlazorTests1; #if (testFramework_xunit) public class CounterCSharpTests : TestContext #elif (testFramework_xunitv3) +// The full qualified namespace for bUnit TestContext is used here as xunit v3 also offers a TestContext class public class CounterCSharpTests : Bunit.TestContext #elif (testFramework_nunit) public class CounterCSharpTests : BunitTestContext diff --git a/src/bunit.template/template/CounterRazorTests.razor b/src/bunit.template/template/CounterRazorTests.razor index f74a8a4a1..09f4ad12d 100644 --- a/src/bunit.template/template/CounterRazorTests.razor +++ b/src/bunit.template/template/CounterRazorTests.razor @@ -1,6 +1,7 @@ @*#if (testFramework_xunit) *@ @inherits TestContext @*#elif (testFramework_xunitv3)*@ +@* The full qualified namespace for bUnit TestContext is used here as xunit v3 also offers a TestContext class *@ @inherits Bunit.TestContext @*#elif (testFramework_nunit)*@ @inherits BunitTestContext From 77f81e5a3f1b94fdb3905668eb2d4009b0498ce0 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 3 Jan 2025 15:04:13 +0100 Subject: [PATCH 4/7] feat: Add xunit v3 markers --- src/bunit.core/Asserting/ActualExpectedAssertException.cs | 4 +++- .../Extensions/WaitForHelpers/WaitForFailedException.cs | 4 +++- .../Internal/XUnitExceptions/IAssertionException.cs | 6 ++++++ .../Internal/XUnitExceptions/ITestTimeoutException.cs | 6 ++++++ src/bunit.core/ParameterException.cs | 2 +- src/bunit.web/Extensions/ElementRemovedFromDomException.cs | 2 +- 6 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/bunit.core/Internal/XUnitExceptions/IAssertionException.cs create mode 100644 src/bunit.core/Internal/XUnitExceptions/ITestTimeoutException.cs diff --git a/src/bunit.core/Asserting/ActualExpectedAssertException.cs b/src/bunit.core/Asserting/ActualExpectedAssertException.cs index 4a75fdc18..498d302eb 100644 --- a/src/bunit.core/Asserting/ActualExpectedAssertException.cs +++ b/src/bunit.core/Asserting/ActualExpectedAssertException.cs @@ -1,10 +1,12 @@ +using Bunit.Internal.XUnitExceptions; + namespace Bunit.Asserting; /// /// Represents a generic assert exception used when an actual result does not match an expected result. /// [Serializable] -public class ActualExpectedAssertException : Exception +public class ActualExpectedAssertException : Exception, IAssertionException { /// /// Initializes a new instance of the class. diff --git a/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs b/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs index 3b9a8fc25..d84d68cb9 100644 --- a/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs +++ b/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs @@ -1,10 +1,12 @@ +using Bunit.Internal.XUnitExceptions; + namespace Bunit.Extensions.WaitForHelpers; /// /// Represents an exception thrown when the does not complete successfully. /// [Serializable] -public sealed class WaitForFailedException : Exception +public sealed class WaitForFailedException : Exception, ITestTimeoutException { /// /// Initializes a new instance of the class. diff --git a/src/bunit.core/Internal/XUnitExceptions/IAssertionException.cs b/src/bunit.core/Internal/XUnitExceptions/IAssertionException.cs new file mode 100644 index 000000000..bf8db4fd1 --- /dev/null +++ b/src/bunit.core/Internal/XUnitExceptions/IAssertionException.cs @@ -0,0 +1,6 @@ +namespace Bunit.Internal.XUnitExceptions; + +/// +/// This is a marker interface for xUnit.v3 that will cause xUnit to consider the failure cause to be an assertion failure. +/// +internal interface IAssertionException; diff --git a/src/bunit.core/Internal/XUnitExceptions/ITestTimeoutException.cs b/src/bunit.core/Internal/XUnitExceptions/ITestTimeoutException.cs new file mode 100644 index 000000000..aec0961ea --- /dev/null +++ b/src/bunit.core/Internal/XUnitExceptions/ITestTimeoutException.cs @@ -0,0 +1,6 @@ +namespace Bunit.Internal.XUnitExceptions; + +/// +/// This is a marker interface for xUnit.v3 that will cause xUnit to consider the failure cause to be a timeout. +/// +internal interface ITestTimeoutException; diff --git a/src/bunit.core/ParameterException.cs b/src/bunit.core/ParameterException.cs index 66ab60a14..dd9cee220 100644 --- a/src/bunit.core/ParameterException.cs +++ b/src/bunit.core/ParameterException.cs @@ -1,7 +1,7 @@ namespace Bunit.RazorTesting; /// -/// Represents an missing or invalid Blazor parameter on a Blazor component. +/// Represents a missing or invalid Blazor parameter on a Blazor component. /// [Serializable] public sealed class ParameterException : ArgumentException diff --git a/src/bunit.web/Extensions/ElementRemovedFromDomException.cs b/src/bunit.web/Extensions/ElementRemovedFromDomException.cs index 6bc370599..4b0cf2db0 100644 --- a/src/bunit.web/Extensions/ElementRemovedFromDomException.cs +++ b/src/bunit.web/Extensions/ElementRemovedFromDomException.cs @@ -2,7 +2,7 @@ namespace Bunit; /// /// Represents an exception that is thrown when trying to access an element -/// that was previous found in the DOM. +/// that was previously found in the DOM. /// [Serializable] public sealed class ElementRemovedFromDomException : ElementNotFoundException From f4dc1236e0e5c68f7c512e69b6330aa29ba8d436 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Sun, 12 Jan 2025 15:43:39 +0100 Subject: [PATCH 5/7] chore: Update packages --- Directory.Packages.props | 26 +++++++++---------- .../template/Company.BlazorTests1.csproj | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 976600a38..2ca5b22bf 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,7 +6,7 @@ - + @@ -15,15 +15,15 @@ - + - + - + @@ -114,24 +114,24 @@ - + - + - + - - + + - + - - - + + + diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index 46699f241..fe62ba21c 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers From eef852c5357957dfbf844cd177e0e13fc6d3cb65 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Sun, 12 Jan 2025 15:51:39 +0100 Subject: [PATCH 6/7] revert: Sonar as it throws many errors --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 2ca5b22bf..2ea5bcd6f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,7 +6,7 @@ - + From 8dc67ace0b105fe08e62529a3019987caeb579ba Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Sun, 12 Jan 2025 14:57:39 +0000 Subject: [PATCH 7/7] Set version to '1.38' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 2983632ed..9def60208 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.38-preview", + "version": "1.38", "assemblyVersion": { "precision": "revision" },