Skip to content

Commit e774a7e

Browse files
committed
feat: Add templates for xunit.v3
1 parent 4cc05b4 commit e774a7e

File tree

8 files changed

+36
-6
lines changed

8 files changed

+36
-6
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ jobs:
191191
dotnet restore ${{ github.workspace }}/TemplateTestXunit --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }}
192192
dotnet test ${{ github.workspace }}/TemplateTestXunit
193193
194+
- name: ✔ Verify xUnit.v3 template
195+
run: |
196+
dotnet new bunit --framework xunitv3 --no-restore -o ${{ github.workspace }}/TemplateTestXunitv3
197+
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${{ github.workspace }}/TemplateTestXunitv3/Directory.Build.props
198+
echo '<Project><PropertyGroup><ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally></PropertyGroup></Project>' >> ${{ github.workspace }}/TemplateTestXunitv3/Directory.Packages.props
199+
dotnet restore ${{ github.workspace }}/TemplateTestXunitv3 --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }}
200+
dotnet test ${{ github.workspace }}/TemplateTestXunitv3
201+
194202
- name: ✔ Verify NUnit template
195203
run: |
196204
dotnet new bunit --framework nunit --no-restore -o ${{ github.workspace }}/TemplateTestNunit

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Added support for xunit v3 in the bunit.template. By [@linkdotnet](https://github.com/linkdotnet).
12+
913
## [1.37.7] - 2024-12-13
1014

1115
### Added

src/bunit.template/template/.template.config/dotnetcli.host.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"usageExamples": [
1717
"--framework xunit --sdk net8.0",
18+
"--framework xunitv3 --sdk net8.0",
1819
"--framework nunit --sdk net8.0",
1920
"--framework mstest --sdk net8.0"
2021
]

src/bunit.template/template/.template.config/template.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
"description": "xUnit unit testing framework",
5959
"displayName": "xUnit"
6060
},
61+
{
62+
"choice": "xunitv3",
63+
"description": "xUnit v3 unit testing framework",
64+
"displayName": "xUnit v3"
65+
},
6166
{
6267
"choice": "mstest",
6368
"description": "MSTest unit testing framework",
@@ -73,6 +78,10 @@
7378
"type": "computed",
7479
"value": "UnitTestFramework == \"xunit\""
7580
},
81+
"testFramework_xunitv3": {
82+
"type": "computed",
83+
"value": "UnitTestFramework == \"xunitv3\""
84+
},
7685
"testFramework_mstest": {
7786
"type": "computed",
7887
"value": "UnitTestFramework == \"mstest\""

src/bunit.template/template/Company.BlazorTests1.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
</PackageReference>
3333
</ItemGroup>
3434

35+
<ItemGroup Condition="'$(testFramework_xunitv3)' == 'true'">
36+
<PackageReference Include="xunit.v3" Version="1.0.0" />
37+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
38+
<PrivateAssets>all</PrivateAssets>
39+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
40+
</PackageReference>
41+
</ItemGroup>
42+
3543
<ItemGroup Condition="'$(testFramework_nunit)' == 'true'">
3644
<PackageReference Include="NUnit" Version="4.2.2" />
3745
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />

src/bunit.template/template/CounterCSharpTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Company.BlazorTests1;
44
/// These tests are written entirely in C#.
55
/// Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating-basic-tests-in-cs-files
66
/// </summary>
7-
#if (testFramework_xunit)
7+
#if (testFramework_xunit || testFramework_xunitv3)
88
public class CounterCSharpTests : TestContext
99
#elif (testFramework_nunit)
1010
public class CounterCSharpTests : BunitTestContext
@@ -29,7 +29,7 @@ public void CounterStartsAtZero()
2929
cut.Find("p").MarkupMatches("<p>Current count: 0</p>");
3030
}
3131

32-
#if (testFramework_xunit)
32+
#if (testFramework_xunit || testFramework_xunitv3)
3333
[Fact]
3434
#elif (testFramework_nunit)
3535
[Test]

src/bunit.template/template/CounterRazorTests.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@*#if (testFramework_xunit)*@
1+
@*#if (testFramework_xunit || testFramework_xunitv3) *@
22
@inherits TestContext
33
@*#elif (testFramework_nunit)*@
44
@inherits BunitTestContext
@@ -12,7 +12,7 @@ These tests are written entirely in razor and C# syntax.
1212
Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating-basic-tests-in-razor-files
1313

1414
@code {
15-
@*#if (testFramework_xunit)*@
15+
@*#if (testFramework_xunit) || testFramework_xunitv3*@
1616
[Fact]
1717
@*#elif (testFramework_nunit)*@
1818
[Test]
@@ -27,7 +27,7 @@ Learn more at https://bunit.dev/docs/getting-started/writing-tests.html#creating
2727
// Assert that content of the paragraph shows counter at zero
2828
cut.Find("p").MarkupMatches(@<p>Current count: 0</p>);
2929
}
30-
@*#if (testFramework_xunit)*@
30+
@*#if (testFramework_xunit || testFramework_xunitv3)*@
3131
[Fact]
3232
@*#elif (testFramework_nunit)*@
3333
[Test]

src/bunit.template/template/_Imports.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@using Microsoft.Extensions.DependencyInjection
44
@using Bunit
55
@using Bunit.TestDoubles
6-
@*#if (testFramework_xunit)*@
6+
@*#if (testFramework_xunit || testFramework_xunitv3)*@
77
@using Xunit
88
@*#elif (testFramework_nunit)*@
99
@using NUnit.Framework

0 commit comments

Comments
 (0)