Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add templates for xunit.v3 #1634

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 10 additions & 11 deletions src/bunit.template/template/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"modifiers": [
{
"exclude": [ "BunitTestContext.cs" ],
"condition": "(testFramework_xunit)"
"condition": "(testFramework_xunit || testFramework_xunitv3)"
}
]
}
Expand Down 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 All @@ -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",
Expand Down
19 changes: 14 additions & 5 deletions src/bunit.template/template/Company.BlazorTests1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
<Using Include="Bunit.TestDoubles" />
<Using Include="Microsoft.Extensions.DependencyInjection" />
<Using Include="Xunit" Condition="'$(testFramework_xunit)' == 'true'"/>
<Using Include="Xunit" Condition="'$(testFramework_xunitv3)' == 'true'"/>
<Using Include="NUnit.Framework" Condition="'$(testFramework_nunit)' == 'true'"/>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" Condition="'$(testFramework_mstest)' == 'true'"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -32,14 +33,22 @@
</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="NUnit" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

<ItemGroup Condition="'$(testFramework_mstest)' == 'true'">
<PackageReference Include="MSTest.TestAdapter" Version="3.6.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/bunit.template/template/CounterCSharpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Company.BlazorTests1;
/// </summary>
#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)
Expand All @@ -15,6 +17,8 @@ public class CounterCSharpTests : BunitTestContext
{
#if (testFramework_xunit)
[Fact]
#elif (testFramework_xunitv3)
[Fact]
#elif (testFramework_nunit)
[Test]
#elif (testFramework_mstest)
Expand All @@ -31,6 +35,8 @@ public void CounterStartsAtZero()

#if (testFramework_xunit)
[Fact]
#elif (testFramework_xunitv3)
[Fact]
#elif (testFramework_nunit)
[Test]
#elif (testFramework_mstest)
Expand Down
8 changes: 7 additions & 1 deletion src/bunit.template/template/CounterRazorTests.razor
Original file line number Diff line number Diff line change
@@ -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)*@
Expand All @@ -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)*@
Expand All @@ -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)*@
Expand Down
2 changes: 2 additions & 0 deletions src/bunit.template/template/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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)*@
Expand Down
Loading