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/Directory.Packages.props b/Directory.Packages.props index 48d1d7ddb..2ea5bcd6f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,15 +15,15 @@ - + - + - + @@ -114,24 +114,24 @@ - + - + - + - - + + - + - - - + + + 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.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..fe62ba21c 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -11,35 +11,44 @@ + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + all runtime; build; native; contentfiles; analyzers + + + + all + runtime; build; native; contentfiles; analyzers + + + - + - - + + diff --git a/src/bunit.template/template/CounterCSharpTests.cs b/src/bunit.template/template/CounterCSharpTests.cs index 020dfabbd..359fc45c4 100644 --- a/src/bunit.template/template/CounterCSharpTests.cs +++ b/src/bunit.template/template/CounterCSharpTests.cs @@ -6,6 +6,9 @@ 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 #elif (testFramework_mstest) @@ -15,6 +18,8 @@ public class CounterCSharpTests : BunitTestContext { #if (testFramework_xunit) [Fact] +#elif (testFramework_xunitv3) + [Fact] #elif (testFramework_nunit) [Test] #elif (testFramework_mstest) @@ -31,6 +36,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..09f4ad12d 100644 --- a/src/bunit.template/template/CounterRazorTests.razor +++ b/src/bunit.template/template/CounterRazorTests.razor @@ -1,5 +1,8 @@ -@*#if (testFramework_xunit)*@ +@*#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 @*#elif (testFramework_mstest)*@ @@ -14,6 +17,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 +34,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)*@ 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 diff --git a/version.json b/version.json index 4c937cfb9..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.37", + "version": "1.38", "assemblyVersion": { "precision": "revision" },