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 e4bd142
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 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
11 changes: 10 additions & 1 deletion 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 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.v3" 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: 4 additions & 2 deletions src/bunit.template/template/CounterCSharpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ 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)
[TestClass]
public class CounterCSharpTests : BunitTestContext
#endif
{
#if (testFramework_xunit)
#if (testFramework_xunit || testFramework_xunitv3)
[Fact]
#elif (testFramework_nunit)
[Test]
Expand All @@ -29,7 +31,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 e4bd142

Please sign in to comment.