Skip to content

Commit acc0203

Browse files
committed
Update documentation to clarify TUnit's support for Microsoft.Testing.Platform and adjust related content across multiple files
1 parent 3edb4a6 commit acc0203

7 files changed

+73
-91
lines changed

docs/core/testing/microsoft-testing-platform-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The main driving factors for the evolution of the new testing platform are detai
4141
* MSTest. In MSTest, the support of `Microsoft.Testing.Platform` is done via [MSTest runner](unit-testing-mstest-runner-intro.md).
4242
* NUnit. In NUnit, the support of `Microsoft.Testing.Platform` is done via [NUnit runner](unit-testing-nunit-runner-intro.md).
4343
* xUnit.net: In xUnit.net, the support of `Microsoft.Testing.Platform` is done via [xUnit.net runner](https://xunit.net/docs/getting-started/v3/microsoft-testing-platform).
44-
* TUnit: Built entirely on Microsoft.Testing.Platform and doesn't support VSTest. Unlike MSTest, NUnit, and xUnit which support both VSTest and MTP, TUnit only supports MTP. For more information, see [TUnit documentation](https://tunit.dev/) and [Getting started with TUnit](unit-testing-csharp-with-tunit.md).
44+
* TUnit: Built entirely on Microsoft.Testing.Platform and doesn't support VSTest. For more information, see [TUnit documentation](https://tunit.dev/) and [Getting started with TUnit](unit-testing-csharp-with-tunit.md).
4545

4646
## Run and debug tests
4747

docs/core/testing/selective-unit-tests.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ dotnet test --filter <Expression>
3030
| Test framework | Supported properties |
3131
| -------------- | -------------------- |
3232
| MSTest | `FullyQualifiedName`<br>`Name`<br>`ClassName`<br>`Priority`<br>`TestCategory` |
33-
| xUnit | `FullyQualifiedName`<br>`DisplayName`<br>`Traits` |
3433
| NUnit | `FullyQualifiedName`<br>`Name`<br>`Priority`<br>`TestCategory` |
35-
| TUnit | `FullyQualifiedName`<br>`Name`<br>`Category`<br>`Property` |
34+
| xUnit | `FullyQualifiedName`<br>`DisplayName`<br>`Traits` |
3635

3736
* **Operators**
3837

docs/core/testing/unit-testing-code-coverage.md

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,25 @@ There are two types of code coverage tools:
165165

166166
In this section, the focus is on data collector tools.
167167

168-
.NET includes a built-in code coverage data collector, which is also available in Visual Studio. This data collector generates a binary *.coverage* file that can be used to generate reports in Visual Studio. The binary file isn't human-readable, and it must be converted to a human-readable format before it can be used to generate reports outside of Visual Studio.
168+
### Code coverage approaches
169+
170+
.NET provides two different testing platforms, each with its own code coverage approach:
171+
172+
- **VSTest-based frameworks** (MSTest, NUnit, xUnit) - Can use either the built-in .NET code coverage collector or [Coverlet](https://github.com/coverlet-coverage/coverlet), an open-source alternative.
173+
- **Microsoft.Testing.Platform-based frameworks** (TUnit, MSTest runner, NUnit runner, xUnit runner) - Use [Microsoft.Testing.Extensions.CodeCoverage](microsoft-testing-platform-extensions-code-coverage.md).
174+
175+
The built-in .NET code coverage data collector generates a binary *.coverage* file that can be used to generate reports in Visual Studio. The binary file isn't human-readable, and it must be converted to a human-readable format before it can be used to generate reports outside of Visual Studio.
169176

170177
> [!TIP]
171178
> The `dotnet-coverage` tool is a cross-platform tool that can be used to convert the binary coverage test results file to a human-readable format. For more information, see [dotnet-coverage](../additional-tools/dotnet-coverage.md).
172179
173-
[Coverlet](https://github.com/coverlet-coverage/coverlet) is an open-source alternative to the built-in collector. It generates test results as human-readable Cobertura XML files, which can then be used to generate HTML reports. To use Coverlet for code coverage, an existing unit test project must have the appropriate package dependencies, or alternatively rely on [.NET global tooling](../tools/global-tools.md) and the corresponding [coverlet.console](https://www.nuget.org/packages/coverlet.console) NuGet package.
180+
Coverlet generates test results as human-readable Cobertura XML files, which can then be used to generate HTML reports. To use Coverlet for code coverage, an existing unit test project must have the appropriate package dependencies, or alternatively rely on [.NET global tooling](../tools/global-tools.md) and the corresponding [coverlet.console](https://www.nuget.org/packages/coverlet.console) NuGet package.
181+
182+
## Code coverage with VSTest
183+
184+
VSTest is the traditional testing platform used by MSTest, NUnit, and xUnit. For VSTest-based projects, you can use either Coverlet or the built-in .NET code coverage collector.
174185

175-
## Integrate with .NET test
186+
### Using Coverlet with VSTest
176187

177188
The xUnit test project template already integrates with [coverlet.collector](https://www.nuget.org/packages/coverlet.collector) by default.
178189
From the command prompt, change directories to the *XUnit.Coverlet.Collector* project, and run the [`dotnet test`](../tools/dotnet-test.md) command:
@@ -295,70 +306,27 @@ After running this command, an HTML file represents the generated report.
295306

296307
:::image type="content" source="media/test-report.png" lightbox="media/test-report.png" alt-text="Unit test-generated report":::
297308

298-
## Using code coverage with TUnit
309+
## Code coverage with Microsoft.Testing.Platform
299310

300-
TUnit is built on Microsoft.Testing.Platform and uses Microsoft.Testing.Extensions.CodeCoverage for code coverage.
301-
302-
### Creating a TUnit test project with code coverage
303-
304-
To create a TUnit test project with code coverage support:
305-
306-
```dotnetcli
307-
dotnet new install TUnit.Templates
308-
dotnet new tunit -n TUnit.CodeCoverage.Test
309-
```
311+
[Microsoft.Testing.Platform](microsoft-testing-platform-intro.md) is the modern testing platform for .NET. Frameworks built on this platform use [Microsoft.Testing.Extensions.CodeCoverage](microsoft-testing-platform-extensions-code-coverage.md) for code coverage.
310312

311-
Add the project reference to your class library:
313+
The following frameworks support Microsoft.Testing.Platform:
314+
- **MSTest** (via MSTest runner)
315+
- **NUnit** (via NUnit runner)
316+
- **xUnit** (via xUnit runner)
317+
- **TUnit**
312318

313-
```dotnetcli
314-
dotnet add TUnit.CodeCoverage.Test\TUnit.CodeCoverage.Test.csproj reference Numbers\Numbers.csproj
315-
```
319+
### Setting up code coverage with Microsoft.Testing.Platform
316320

317-
Add the Microsoft.Testing.Extensions.CodeCoverage package:
321+
The setup process is consistent across all Microsoft.Testing.Platform-based frameworks. Add the code coverage package to your test project:
318322

319323
```dotnetcli
320-
dotnet add TUnit.CodeCoverage.Test package Microsoft.Testing.Extensions.CodeCoverage
324+
dotnet add package Microsoft.Testing.Extensions.CodeCoverage
321325
```
322326

323-
### TUnit test example
324-
325-
```csharp
326-
using TUnit.Assertions;
327-
using TUnit.Assertions.Extensions;
328-
using TUnit.Core;
329-
using System.Numbers;
330-
331-
public class PrimeServiceTests
332-
{
333-
[Test]
334-
public async Task IsPrime_InputIs1_ReturnFalse()
335-
{
336-
var primeService = new PrimeService();
327+
### Configuring Microsoft.Testing.Platform mode
337328

338-
bool result = primeService.IsPrime(1);
339-
340-
await Assert.That(result).IsFalse();
341-
}
342-
343-
[Test]
344-
[Arguments(2)]
345-
[Arguments(3)]
346-
[Arguments(5)]
347-
[Arguments(7)]
348-
public async Task IsPrime_PrimesLessThan10_ReturnTrue(int value)
349-
{
350-
var primeService = new PrimeService();
351-
352-
bool result = primeService.IsPrime(value);
353-
354-
await Assert.That(result).IsTrue();
355-
}
356-
}
357-
```
358-
359-
### Running code coverage with TUnit
360-
361-
Since TUnit requires Microsoft.Testing.Platform mode, ensure your `global.json` includes:
329+
Some frameworks require Microsoft.Testing.Platform mode to be explicitly configured. Add this configuration to your `global.json` file in the solution root:
362330

363331
```json
364332
{
@@ -368,19 +336,36 @@ Since TUnit requires Microsoft.Testing.Platform mode, ensure your `global.json`
368336
}
369337
```
370338

371-
Run tests with code coverage:
339+
> [!NOTE]
340+
> This configuration requires .NET 10 SDK or later. Frameworks like MSTest runner, NUnit runner, and xUnit runner support both VSTest and Microsoft.Testing.Platform, so this configuration is optional for those frameworks. TUnit only supports Microsoft.Testing.Platform, so this configuration is required.
341+
342+
### Running code coverage
343+
344+
Run tests with code coverage using the `--coverage` flag:
372345

373346
```dotnetcli
374347
dotnet test --coverage
375348
```
376349

377-
This generates a `.coverage` file in the `TestResults` directory. To generate reports in other formats:
350+
This generates a `.coverage` file in the `TestResults` directory. The `--coverage` flag is specific to Microsoft.Testing.Platform and provides a unified code coverage experience across all supported frameworks.
351+
352+
To generate reports in other formats, use the `--coverage-output-format` option:
378353

379354
```dotnetcli
380355
dotnet test --coverage --coverage-output-format cobertura
381356
```
382357

383-
For more information about TUnit, see [Unit testing C# with TUnit](unit-testing-csharp-with-tunit.md).
358+
Supported output formats include:
359+
- `coverage` (binary format, default)
360+
- `cobertura` (XML format)
361+
- `xml` (XML format)
362+
363+
### Framework-specific documentation
364+
365+
For detailed information about using Microsoft.Testing.Platform with specific frameworks, see:
366+
- [Unit testing with MSTest runner](unit-testing-mstest-runner-intro.md)
367+
- [Unit testing with NUnit runner](unit-testing-nunit-runner-intro.md)
368+
- [Unit testing C# with TUnit](unit-testing-csharp-with-tunit.md)
384369

385370
## See also
386371

docs/core/testing/unit-testing-csharp-with-tunit.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ ai-usage: ai-assisted
88
---
99
# Unit testing C# in .NET using dotnet test and TUnit
1010

11-
This tutorial shows how to build a solution containing a unit test project and source code project. To follow the tutorial using a prebuilt solution, [view or download the sample code](https://github.com/dotnet/samples/tree/main/core/getting-started/unit-testing-using-dotnet-test/). For download instructions, see [Samples and Tutorials](../../samples-and-tutorials/index.md#view-and-download-samples).
11+
This tutorial shows how to build a solution containing a unit test project and source code project step-by-step.
1212

1313
## Prerequisites
1414

15-
TUnit is built entirely on [Microsoft.Testing.Platform](microsoft-testing-platform-intro.md). Unlike frameworks that support both VSTest and Microsoft.Testing.Platform, TUnit only supports Microsoft.Testing.Platform.
15+
TUnit is built entirely on [Microsoft.Testing.Platform](microsoft-testing-platform-intro.md) and does not support VSTest.
1616

1717
## Create the solution
1818

@@ -125,6 +125,9 @@ Follow the instructions for "Replace the code in *PrimeService.cs* with the foll
125125

126126
TUnit only supports Microsoft.Testing.Platform and doesn't support VSTest. To use `dotnet test` with TUnit, add the following configuration to your `global.json` file in the solution root:
127127

128+
> [!NOTE]
129+
> This configuration requires .NET 10 SDK or later.
130+
128131
```json
129132
{
130133
"test": {

docs/core/testing/unit-testing-fsharp-with-tunit.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ ai-usage: ai-assisted
88
---
99
# Unit testing F# libraries in .NET Core using dotnet test and TUnit
1010

11-
This tutorial takes you through an interactive experience building a sample solution step-by-step to learn unit testing concepts. If you prefer to follow the tutorial using a pre-built solution, [view or download the sample code](https://github.com/dotnet/samples/tree/main/core/getting-started/unit-testing-with-fsharp/) before you begin. For download instructions, see [Samples and Tutorials](../../samples-and-tutorials/index.md#view-and-download-samples).
11+
This tutorial takes you through an interactive experience building a sample solution step-by-step to learn unit testing concepts.
1212

1313
[!INCLUDE [testing an ASP.NET Core project from .NET Core](../../../includes/core-testing-note-aspnet.md)]
1414

1515
## Prerequisites
1616

17-
TUnit is built entirely on [Microsoft.Testing.Platform](microsoft-testing-platform-intro.md). Unlike frameworks that support both VSTest and Microsoft.Testing.Platform, TUnit only supports Microsoft.Testing.Platform.
17+
TUnit is built entirely on [Microsoft.Testing.Platform](microsoft-testing-platform-intro.md) and does not support VSTest.
1818

1919
## Creating the source project
2020

docs/core/testing/unit-testing-visual-basic-with-tunit.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ ai-usage: ai-assisted
88
---
99
# Unit testing Visual Basic .NET Core libraries using dotnet test and TUnit
1010

11-
This tutorial shows how to build a solution containing a unit test project and library project. To follow the tutorial using a pre-built solution, [view or download the sample code](https://github.com/dotnet/samples/tree/main/core/getting-started/unit-testing-using-dotnet-test/). For download instructions, see [Samples and Tutorials](../../samples-and-tutorials/index.md#view-and-download-samples).
11+
This tutorial shows how to build a solution containing a unit test project and library project step-by-step.
1212

1313
## Prerequisites
1414

15-
TUnit is built entirely on [Microsoft.Testing.Platform](microsoft-testing-platform-intro.md). Unlike frameworks that support both VSTest and Microsoft.Testing.Platform, TUnit only supports Microsoft.Testing.Platform.
15+
TUnit is built entirely on [Microsoft.Testing.Platform](microsoft-testing-platform-intro.md) and does not support VSTest.
1616

1717
## Create the solution
1818

@@ -102,8 +102,6 @@ The following instructions provide the steps to create the test solution. See [C
102102
dotnet add ./PrimeService.Tests/PrimeService.Tests.vbproj reference ./PrimeService/PrimeService.vbproj
103103
```
104104

105-
<a name="create-test-cmd"></a>
106-
107105
### Commands to create the solution
108106

109107
This section summarizes all the commands in the previous section. Skip this section if you've completed the steps in the previous section.
@@ -152,21 +150,20 @@ Update the *PrimeService.Tests* project:
152150
Imports TUnit.Assertions
153151
Imports TUnit.Assertions.Extensions
154152
Imports TUnit.Core
153+
Imports Prime.Services
155154

156155
Namespace PrimeService.Tests
157156
Public Class PrimeService_IsPrimeShould
158-
Private ReadOnly _primeService As Prime.Services.PrimeService
157+
Private ReadOnly _primeService As PrimeService
159158

160159
Public Sub New()
161-
_primeService = New Prime.Services.PrimeService()
160+
_primeService = New PrimeService()
162161
End Sub
163162

164163
<Test>
165-
Function IsPrime_InputIs1_ReturnFalse() As Task
166-
Return Task.Run(Async Function()
167-
Dim result As Boolean = _primeService.IsPrime(1)
168-
Await Assert.That(result).IsFalse()
169-
End Function)
164+
Public Async Function IsPrime_InputIs1_ReturnFalse() As Task
165+
Dim result As Boolean = _primeService.IsPrime(1)
166+
Await Assert.That(result).IsFalse()
170167
End Function
171168

172169
End Class
@@ -206,11 +203,9 @@ Rather than creating new tests, apply the `[Arguments]` attribute to create para
206203

207204
```vb
208205
<Test>
209-
Function IsPrime_InputIs1_ReturnFalse() As Task
210-
Return Task.Run(Async Function()
211-
Dim result As Boolean = _primeService.IsPrime(1)
212-
Await Assert.That(result).IsFalse()
213-
End Function)
206+
Public Async Function IsPrime_InputIs1_ReturnFalse() As Task
207+
Dim result As Boolean = _primeService.IsPrime(1)
208+
Await Assert.That(result).IsFalse()
214209
End Function
215210
```
216211

@@ -221,11 +216,9 @@ with the following code:
221216
<Arguments(-1)>
222217
<Arguments(0)>
223218
<Arguments(1)>
224-
Function IsPrime_ValuesLessThan2_ReturnFalse(ByVal value As Integer) As Task
225-
Return Task.Run(Async Function()
226-
Dim result As Boolean = _primeService.IsPrime(value)
227-
Await Assert.That(result).IsFalse()
228-
End Function)
219+
Public Async Function IsPrime_ValuesLessThan2_ReturnFalse(ByVal value As Integer) As Task
220+
Dim result As Boolean = _primeService.IsPrime(value)
221+
Await Assert.That(result).IsFalse()
229222
End Function
230223
```
231224

docs/zone-pivot-groups.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ groups:
3434
pivots:
3535
- id: mstest
3636
title: MSTest
37-
- id: xunit
38-
title: xUnit
3937
- id: nunit
4038
title: NUnit
39+
- id: tunit
40+
title: TUnit
41+
- id: xunit
42+
title: xUnit
4143
- id: ide-set-one
4244
title: IDE
4345
prompt: Choose an IDE

0 commit comments

Comments
 (0)