Skip to content

Commit

Permalink
feat: Add templates for xunit.v3
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Dec 17, 2024
1 parent 4cc05b4 commit e774a7e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${{ github.workspace }}/TemplateTestXunitv3/Directory.Build.props
echo '<Project><PropertyGroup><ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally></PropertyGroup></Project>' >> ${{ 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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
9 changes: 9 additions & 0 deletions src/bunit.template/template/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -73,6 +78,10 @@
"type": "computed",
"value": "UnitTestFramework == \"xunit\""
},
"testFramework_xunitv3": {
"type": "computed",
"value": "UnitTestFramework == \"xunitv3\""
},
"testFramework_mstest": {
"type": "computed",
"value": "UnitTestFramework == \"mstest\""
Expand Down
8 changes: 8 additions & 0 deletions src/bunit.template/template/Company.BlazorTests1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(testFramework_xunitv3)' == 'true'">
<PackageReference Include="xunit.v3" Version="1.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(testFramework_nunit)' == 'true'">
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
Expand Down
4 changes: 2 additions & 2 deletions src/bunit.template/template/CounterCSharpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Company.BlazorTests1;
/// These tests are written entirely in C#.
/// Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating-basic-tests-in-cs-files
/// </summary>
#if (testFramework_xunit)
#if (testFramework_xunit || testFramework_xunitv3)
public class CounterCSharpTests : TestContext
#elif (testFramework_nunit)
public class CounterCSharpTests : BunitTestContext
Expand All @@ -29,7 +29,7 @@ public void CounterStartsAtZero()
cut.Find("p").MarkupMatches("<p>Current count: 0</p>");
}

#if (testFramework_xunit)
#if (testFramework_xunit || testFramework_xunitv3)
[Fact]
#elif (testFramework_nunit)
[Test]
Expand Down
6 changes: 3 additions & 3 deletions src/bunit.template/template/CounterRazorTests.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@*#if (testFramework_xunit)*@
@*#if (testFramework_xunit || testFramework_xunitv3) *@
@inherits TestContext
@*#elif (testFramework_nunit)*@
@inherits BunitTestContext
Expand All @@ -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]
Expand All @@ -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(@<p>Current count: 0</p>);
}
@*#if (testFramework_xunit)*@
@*#if (testFramework_xunit || testFramework_xunitv3)*@
[Fact]
@*#elif (testFramework_nunit)*@
[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.template/template/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e774a7e

Please sign in to comment.