Skip to content

Commit 435230f

Browse files
committed
docs: tunit and some adoptions for xunit.v3
1 parent 6728ad2 commit 435230f

File tree

3 files changed

+97
-24
lines changed

3 files changed

+97
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- Pass parameters, cascading values and inject services into components under test
1313
- Mock `IJSRuntime`, Blazor authentication and authorization, and others
1414

15-
bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, and MSTest, which run the Blazor component tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
15+
bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, MSTest and TUnit, which run the Blazor component tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
1616

1717
**Go to [bUnit.dev](https://bunit.dev) to learn more.**
1818

docs/site/docs/getting-started/create-test-project.md

Lines changed: 95 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ These steps look like this from the `dotnet` CLI:
2525

2626
Install the template from NuGet using this command:
2727

28-
```dotnetcli
29-
dotnet new --install bunit.template
30-
```
31-
32-
Or, since .NET 7 onwards:
33-
3428
```dotnetcli
3529
dotnet new install bunit.template
3630
```
@@ -49,12 +43,19 @@ the framework of your choice:
4943
dotnet new bunit --framework xunit -o <NAME OF TEST PROJECT>
5044
```
5145

46+
# [xUnit v3](#tab/xunitv3)
47+
48+
```dotnetcli
49+
dotnet new bunit --framework xunitv3 -o <NAME OF TEST PROJECT>
50+
```
51+
5252
# [NUnit](#tab/nunit)
5353

5454
```dotnetcli
5555
dotnet new bunit --framework nunit -o <NAME OF TEST PROJECT>
5656
```
5757

58+
5859
# [MSTest](#tab/mstest)
5960

6061
```dotnetcli
@@ -65,7 +66,7 @@ dotnet new bunit --framework mstest -o <NAME OF TEST PROJECT>
6566

6667
The `--framework` option in the `dotnet new` command above is used to specify the unit testing framework used by the test project. If the `--framework` option is omitted, the default test framework `xunit` will be configured. Currently supported options are the following:
6768

68-
- `xunit` - [xUnit](https://xunit.net/),
69+
- `xunit` and `xunitv3` - [xUnit](https://xunit.net/),
6970
- `nunit` - [NUnit](https://nunit.org/),
7071
- `mstest` - [MSTest](https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest)
7172

@@ -84,7 +85,7 @@ This will allow the test project to see and test the components in the component
8485

8586
This section will take you through the steps required to create a project for testing Blazor components using bUnit. Any of the three general-purpose test frameworks shown in step 1 below can be used. Briefly, here is what we will do:
8687

87-
1. Create a new xUnit/NUnit/MSTest testing project
88+
1. Create a new xUnit/NUnit/MSTest/TUnit testing project
8889
2. Add bUnit to the test project
8990
3. Configure project settings
9091
4. Add the test project to your existing solution
@@ -101,6 +102,12 @@ Use the following command (_click on the tab for the test framework of choice_):
101102
dotnet new xunit -o <NAME OF TEST PROJECT>
102103
```
103104

105+
# [xUnit v3](#tab/xunitv3)
106+
107+
```dotnetcli
108+
dotnet new xunit3 -o <NAME OF TEST PROJECT>
109+
```
110+
104111
# [NUnit](#tab/nunit)
105112

106113
```dotnetcli
@@ -113,6 +120,12 @@ dotnet new nunit -o <NAME OF TEST PROJECT>
113120
dotnet new mstest -o <NAME OF TEST PROJECT>
114121
```
115122

123+
# [TUnit](#tab/tunit)
124+
125+
```dotnetcli
126+
dotnet new TUnit -o <NAME OF TEST PROJECT>
127+
```
128+
116129
***
117130

118131
The `-o` option in the `dotnet new` command above is used to specify the name of the test project.
@@ -130,11 +143,11 @@ dotnet add package bunit --version #{NBGV_NuGetPackageVersion}#
130143

131144
The test projects setting needs to be set to the following:
132145

133-
- the project's SDK needs to be set to `Microsoft.NET.Sdk.Razor`
146+
- the project's SDK needs to be set to `Microsoft.NET.Sdk.Razor` (this does not work with **TUnit** - a more detailed explanation can be found below)
134147
- set the `<TargetFramework>` to `net8.0`
135148

136149
> [!NOTE]
137-
> bUnit works with `net7.0`, `net6.0`, `net5.0` and `netcoreapp3.1`/`netstandard2.1` test projects as well.
150+
> bUnit works with `net8.0` and above as well.
138151
139152
To do so, change the first part of the test projects `.csproj` file to look like this.:
140153

@@ -172,13 +185,43 @@ The result should be a test project with a `.csproj` that looks like this (non b
172185

173186
<ItemGroup>
174187
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
175-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
176-
<PackageReference Include="xunit" Version="2.8.1" />
177-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
188+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
189+
<PackageReference Include="xunit" Version="2.9.4" />
190+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
191+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
192+
<PrivateAssets>all</PrivateAssets>
193+
</PackageReference>
194+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
195+
</ItemGroup>
196+
197+
<ItemGroup>
198+
<ProjectReference Include="<PATH TO COMPONENT LIB>.csproj" />
199+
</ItemGroup>
200+
201+
</Project>
202+
```
203+
204+
# [xUnit v3](#tab/xunitv3)
205+
206+
```xml
207+
<Project Sdk="Microsoft.NET.Sdk.Razor">
208+
209+
<PropertyGroup>
210+
<TargetFramework>net8.0</TargetFramework>
211+
<Nullable>enable</Nullable>
212+
<IsPackable>false</IsPackable>
213+
<OutputType>Exe</OutputType>
214+
</PropertyGroup>
215+
216+
<ItemGroup>
217+
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
218+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
219+
<PackageReference Include="xunit.v3" Version="1.0.1" />
220+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
178221
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
179222
<PrivateAssets>all</PrivateAssets>
180223
</PackageReference>
181-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
224+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
182225
</ItemGroup>
183226

184227
<ItemGroup>
@@ -201,10 +244,10 @@ The result should be a test project with a `.csproj` that looks like this (non b
201244

202245
<ItemGroup>
203246
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
204-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
205-
<PackageReference Include="NUnit" Version="3.14.0" />
206-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
207-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
247+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
248+
<PackageReference Include="NUnit" Version="4.3.2" />
249+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
250+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
208251
</ItemGroup>
209252

210253
<ItemGroup>
@@ -227,10 +270,35 @@ The result should be a test project with a `.csproj` that looks like this (non b
227270

228271
<ItemGroup>
229272
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
230-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
231-
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
232-
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
233-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
273+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
274+
<PackageReference Include="MSTest.TestAdapter" Version="3.7.1" />
275+
<PackageReference Include="MSTest.TestFramework" Version="3.7.1" />
276+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
277+
</ItemGroup>
278+
279+
<ItemGroup>
280+
<ProjectReference Include="<PATH TO COMPONENT LIB>.csproj" />
281+
</ItemGroup>
282+
283+
</Project>
284+
```
285+
286+
# [TUnit](#tab/tunit)
287+
288+
```xml
289+
<Project Sdk="Microsoft.NET.Sdk">
290+
291+
<PropertyGroup>
292+
<TargetFramework>net8.0</TargetFramework>
293+
<Nullable>enable</Nullable>
294+
<IsPackable>false</IsPackable>
295+
<IsTestingPlatformApplication>false</IsTestingPlatformApplication>
296+
</PropertyGroup>
297+
298+
<ItemGroup>
299+
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
300+
<PackageReference Include="TUnit" Version="0.6.154" />
301+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
234302
</ItemGroup>
235303

236304
<ItemGroup>
@@ -240,6 +308,11 @@ The result should be a test project with a `.csproj` that looks like this (non b
240308
</Project>
241309
```
242310

311+
> [!WARNING]
312+
> **TUnit** and the `Microsoft.NET.Sdk.Razor` both utilize source code generators. Source generators can not see or interact with the output of another generator. Therefore **TUnit** does not work with `razor` files. Using `cs` based tests is working perfectly fine. For more information regarding the setup of **TUnit** head over to: https://github.com/thomhurst/TUnit
313+
314+
***
315+
243316
## Further reading
244317

245318
To start creating tests, continue reading the <xref:writing-tests> page.

docs/site/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ title: bUnit - a testing library for Blazor components
1717
- Pass parameters, cascading values and inject services into components under test
1818
- Mock `IJSRuntime`, Blazor authentication and authorization, and others
1919

20-
bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, and MSTest, which run the Blazor components tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
20+
bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, MSTest and TUnit, which run the Blazor components tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
2121

2222
**Go to the [Documentation](xref:getting-started) pages to learn more.**
2323

0 commit comments

Comments
 (0)