diff --git a/README.md b/README.md index 5c3d70e75..5dd77672f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ - Pass parameters, cascading values and inject services into components under test - Mock `IJSRuntime`, Blazor authentication and authorization, and others -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. +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. **Go to [bUnit.dev](https://bunit.dev) to learn more.** diff --git a/docs/site/docs/getting-started/create-test-project.md b/docs/site/docs/getting-started/create-test-project.md index 09fc5f164..de3e4a430 100644 --- a/docs/site/docs/getting-started/create-test-project.md +++ b/docs/site/docs/getting-started/create-test-project.md @@ -25,12 +25,6 @@ These steps look like this from the `dotnet` CLI: Install the template from NuGet using this command: -```dotnetcli -dotnet new --install bunit.template -``` - -Or, since .NET 7 onwards: - ```dotnetcli dotnet new install bunit.template ``` @@ -49,23 +43,34 @@ the framework of your choice: dotnet new bunit --framework xunit -o ``` +# [xUnit v3](#tab/xunitv3) + +```dotnetcli +dotnet new bunit --framework xunitv3 -o +``` + # [NUnit](#tab/nunit) ```dotnetcli dotnet new bunit --framework nunit -o ``` + # [MSTest](#tab/mstest) ```dotnetcli dotnet new bunit --framework mstest -o ``` +# [TUnit](#tab/tunit) + +There is no prebuilt template for **TUnit**. More information on how to set up a **TUnit** project can be found down below. + *** 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: -- `xunit` - [xUnit](https://xunit.net/), +- `xunit` and `xunitv3` - [xUnit](https://xunit.net/), - `nunit` - [NUnit](https://nunit.org/), - `mstest` - [MSTest](https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest) @@ -84,7 +89,7 @@ This will allow the test project to see and test the components in the component 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: -1. Create a new xUnit/NUnit/MSTest testing project +1. Create a new xUnit/NUnit/MSTest/TUnit testing project 2. Add bUnit to the test project 3. Configure project settings 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_): dotnet new xunit -o ``` +# [xUnit v3](#tab/xunitv3) + +```dotnetcli +dotnet new xunit3 -o +``` + # [NUnit](#tab/nunit) ```dotnetcli @@ -113,6 +124,12 @@ dotnet new nunit -o dotnet new mstest -o ``` +# [TUnit](#tab/tunit) + +```dotnetcli +dotnet new TUnit -o +``` + *** 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}# The test projects setting needs to be set to the following: -- the project's SDK needs to be set to `Microsoft.NET.Sdk.Razor` +- 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) - set the `` to `net8.0` > [!NOTE] -> bUnit works with `net7.0`, `net6.0`, `net5.0` and `netcoreapp3.1`/`netstandard2.1` test projects as well. +> bUnit works with `net8.0` and above as well. To do so, change the first part of the test projects `.csproj` file to look like this.: @@ -172,13 +189,43 @@ The result should be a test project with a `.csproj` that looks like this (non b - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + +``` + +# [xUnit v3](#tab/xunitv3) + +```xml + + + + net8.0 + enable + false + Exe + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + @@ -201,10 +248,10 @@ The result should be a test project with a `.csproj` that looks like this (non b - - - - + + + + @@ -227,10 +274,10 @@ The result should be a test project with a `.csproj` that looks like this (non b - - - - + + + + @@ -240,6 +287,36 @@ The result should be a test project with a `.csproj` that looks like this (non b ``` +# [TUnit](#tab/tunit) + +```xml + + + + net8.0 + enable + false + false + + + + + + + + + + + + + +``` + +> [!WARNING] +> **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 + +*** + ## Further reading To start creating tests, continue reading the page. diff --git a/docs/site/index.md b/docs/site/index.md index 9d0242daa..6441570e5 100644 --- a/docs/site/index.md +++ b/docs/site/index.md @@ -17,7 +17,7 @@ title: bUnit - a testing library for Blazor components - Pass parameters, cascading values and inject services into components under test - Mock `IJSRuntime`, Blazor authentication and authorization, and others -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. +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. **Go to the [Documentation](xref:getting-started) pages to learn more.**