Skip to content

Commit 4a750e5

Browse files
authored
docs: initial docs about tunit and some adoptions for xunit.v3
1 parent c9660d1 commit 4a750e5

File tree

3 files changed

+93
-25
lines changed

3 files changed

+93
-25
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: 90 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,9 +66,10 @@ 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)
72+
- `tunit` - [TUnit](https://github.com/thomhurst/TUnit)
7173

7274
**3. Add the test project to your solution**
7375

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

8587
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:
8688

87-
1. Create a new xUnit/NUnit/MSTest testing project
89+
1. Create a new xUnit/NUnit/MSTest/TUnit testing project
8890
2. Add bUnit to the test project
8991
3. Configure project settings
9092
4. Add the test project to your existing solution
@@ -101,6 +103,12 @@ Use the following command (_click on the tab for the test framework of choice_):
101103
dotnet new xunit -o <NAME OF TEST PROJECT>
102104
```
103105

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

106114
```dotnetcli
@@ -130,11 +138,11 @@ dotnet add package bunit --version #{NBGV_NuGetPackageVersion}#
130138

131139
The test projects setting needs to be set to the following:
132140

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

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

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

173181
<ItemGroup>
174182
<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">
183+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
184+
<PackageReference Include="xunit" Version="2.9.4" />
185+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
186+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
187+
<PrivateAssets>all</PrivateAssets>
188+
</PackageReference>
189+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
190+
</ItemGroup>
191+
192+
<ItemGroup>
193+
<ProjectReference Include="<PATH TO COMPONENT LIB>.csproj" />
194+
</ItemGroup>
195+
196+
</Project>
197+
```
198+
199+
# [xUnit v3](#tab/xunitv3)
200+
201+
```xml
202+
<Project Sdk="Microsoft.NET.Sdk.Razor">
203+
204+
<PropertyGroup>
205+
<TargetFramework>net8.0</TargetFramework>
206+
<Nullable>enable</Nullable>
207+
<IsPackable>false</IsPackable>
208+
<OutputType>Exe</OutputType>
209+
</PropertyGroup>
210+
211+
<ItemGroup>
212+
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
213+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
214+
<PackageReference Include="xunit.v3" Version="1.0.1" />
215+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
178216
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
179217
<PrivateAssets>all</PrivateAssets>
180218
</PackageReference>
181-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
219+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
182220
</ItemGroup>
183221

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

202240
<ItemGroup>
203241
<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" />
242+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
243+
<PackageReference Include="NUnit" Version="4.3.2" />
244+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
245+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
208246
</ItemGroup>
209247

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

228266
<ItemGroup>
229267
<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" />
268+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
269+
<PackageReference Include="MSTest.TestAdapter" Version="3.7.1" />
270+
<PackageReference Include="MSTest.TestFramework" Version="3.7.1" />
271+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
272+
</ItemGroup>
273+
274+
<ItemGroup>
275+
<ProjectReference Include="<PATH TO COMPONENT LIB>.csproj" />
276+
</ItemGroup>
277+
278+
</Project>
279+
```
280+
281+
# [TUnit](#tab/tunit)
282+
283+
```xml
284+
<Project Sdk="Microsoft.NET.Sdk">
285+
286+
<PropertyGroup>
287+
<TargetFramework>net8.0</TargetFramework>
288+
<Nullable>enable</Nullable>
289+
<IsPackable>false</IsPackable>
290+
<IsTestingPlatformApplication>false</IsTestingPlatformApplication>
291+
</PropertyGroup>
292+
293+
<ItemGroup>
294+
<PackageReference Include="bunit" Version="#{RELEASE_VERSION}#" />
295+
<PackageReference Include="TUnit" Version="0.6.154" />
296+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
234297
</ItemGroup>
235298

236299
<ItemGroup>
@@ -240,6 +303,11 @@ The result should be a test project with a `.csproj` that looks like this (non b
240303
</Project>
241304
```
242305

306+
> [!WARNING]
307+
> **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
308+
309+
***
310+
243311
## Further reading
244312

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

docs/site/index.md

Lines changed: 2 additions & 2 deletions
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

@@ -44,7 +44,7 @@ bUnit is available on NuGet in various incarnations. Most users should just pick
4444
| [bUnit](https://www.nuget.org/packages/bunit/) | Includes the bUnit.core and bUnit.web packages. | [![Nuget](https://img.shields.io/nuget/dt/bunit?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit/) |
4545
| [bUnit.core](https://www.nuget.org/packages/bunit.core/) | Core library that enables rendering a Blazor component in a test context. | [![Nuget](https://img.shields.io/nuget/dt/bunit.core?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.core/) |
4646
| [bUnit.web](https://www.nuget.org/packages/bunit.web/) | Adds support for testing Blazor components for the web. This includes bUnit.core. | [![Nuget](https://img.shields.io/nuget/dt/bunit.web?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.web/) |
47-
| [bUnit.template](https://www.nuget.org/packages/bunit.template/) | Template for bUnit test projects based on xUnit, NUnit or MSTest | [![Nuget](https://img.shields.io/nuget/dt/bunit.template?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.template/) |
47+
| [bUnit.template](https://www.nuget.org/packages/bunit.template/) | Template for bUnit test projects based on xUnit, NUnit, MSTest or TUnit | [![Nuget](https://img.shields.io/nuget/dt/bunit.template?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.template/) |
4848
| [bUnit.generators](https://www.nuget.org/packages/bunit.generators/)|Source code generators to minimize code setup in various situations.|[![Nuget](https://img.shields.io/nuget/dt/bunit.generators?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.generators/)|
4949
| [bUnit.web.query](https://www.nuget.org/packages/bunit.web.query/)|bUnit implementation of testing-library.com's query APIs.|[![Nuget](https://img.shields.io/nuget/dt/bunit.web.query?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.web.query/)|
5050

0 commit comments

Comments
 (0)