Skip to content

Commit 6caa87f

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

File tree

3 files changed

+101
-24
lines changed

3 files changed

+101
-24
lines changed

README.md

+1-1
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

+99-22
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,23 +43,34 @@ 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
6162
dotnet new bunit --framework mstest -o <NAME OF TEST PROJECT>
6263
```
6364

65+
# [TUnit](#tab/tunit)
66+
67+
There is no prebuilt template for **TUnit**. More information on how to set up a **TUnit** project can be found down below.
68+
6469
***
6570

6671
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:
6772

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

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

8590
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:
8691

87-
1. Create a new xUnit/NUnit/MSTest testing project
92+
1. Create a new xUnit/NUnit/MSTest/TUnit testing project
8893
2. Add bUnit to the test project
8994
3. Configure project settings
9095
4. Add the test project to your existing solution
@@ -101,6 +106,12 @@ Use the following command (_click on the tab for the test framework of choice_):
101106
dotnet new xunit -o <NAME OF TEST PROJECT>
102107
```
103108

109+
# [xUnit v3](#tab/xunitv3)
110+
111+
```dotnetcli
112+
dotnet new xunit3 -o <NAME OF TEST PROJECT>
113+
```
114+
104115
# [NUnit](#tab/nunit)
105116

106117
```dotnetcli
@@ -113,6 +124,12 @@ dotnet new nunit -o <NAME OF TEST PROJECT>
113124
dotnet new mstest -o <NAME OF TEST PROJECT>
114125
```
115126

127+
# [TUnit](#tab/tunit)
128+
129+
```dotnetcli
130+
dotnet new TUnit -o <NAME OF TEST PROJECT>
131+
```
132+
116133
***
117134

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

131148
The test projects setting needs to be set to the following:
132149

133-
- the project's SDK needs to be set to `Microsoft.NET.Sdk.Razor`
150+
- 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)
134151
- set the `<TargetFramework>` to `net8.0`
135152

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

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

173190
<ItemGroup>
174191
<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">
192+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
193+
<PackageReference Include="xunit" Version="2.9.4" />
194+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
195+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
196+
<PrivateAssets>all</PrivateAssets>
197+
</PackageReference>
198+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
199+
</ItemGroup>
200+
201+
<ItemGroup>
202+
<ProjectReference Include="<PATH TO COMPONENT LIB>.csproj" />
203+
</ItemGroup>
204+
205+
</Project>
206+
```
207+
208+
# [xUnit v3](#tab/xunitv3)
209+
210+
```xml
211+
<Project Sdk="Microsoft.NET.Sdk.Razor">
212+
213+
<PropertyGroup>
214+
<TargetFramework>net8.0</TargetFramework>
215+
<Nullable>enable</Nullable>
216+
<IsPackable>false</IsPackable>
217+
<OutputType>Exe</OutputType>
218+
</PropertyGroup>
219+
220+
<ItemGroup>
221+
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
222+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
223+
<PackageReference Include="xunit.v3" Version="1.0.1" />
224+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
178225
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
179226
<PrivateAssets>all</PrivateAssets>
180227
</PackageReference>
181-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
228+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
182229
</ItemGroup>
183230

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

202249
<ItemGroup>
203250
<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" />
251+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
252+
<PackageReference Include="NUnit" Version="4.3.2" />
253+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
254+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
208255
</ItemGroup>
209256

210257
<ItemGroup>
@@ -227,10 +274,10 @@ The result should be a test project with a `.csproj` that looks like this (non b
227274

228275
<ItemGroup>
229276
<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" />
277+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
278+
<PackageReference Include="MSTest.TestAdapter" Version="3.7.1" />
279+
<PackageReference Include="MSTest.TestFramework" Version="3.7.1" />
280+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
234281
</ItemGroup>
235282

236283
<ItemGroup>
@@ -240,6 +287,36 @@ The result should be a test project with a `.csproj` that looks like this (non b
240287
</Project>
241288
```
242289

290+
# [TUnit](#tab/tunit)
291+
292+
```xml
293+
<Project Sdk="Microsoft.NET.Sdk">
294+
295+
<PropertyGroup>
296+
<TargetFramework>net8.0</TargetFramework>
297+
<Nullable>enable</Nullable>
298+
<IsPackable>false</IsPackable>
299+
<IsTestingPlatformApplication>false</IsTestingPlatformApplication>
300+
</PropertyGroup>
301+
302+
<ItemGroup>
303+
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
304+
<PackageReference Include="TUnit" Version="0.6.154" />
305+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
306+
</ItemGroup>
307+
308+
<ItemGroup>
309+
<ProjectReference Include="<PATH TO COMPONENT LIB>.csproj" />
310+
</ItemGroup>
311+
312+
</Project>
313+
```
314+
315+
> [!WARNING]
316+
> **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
317+
318+
***
319+
243320
## Further reading
244321

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

docs/site/index.md

+1-1
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)