Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# .NET testing samples

This directory contains minimal examples that demonstrate how to use common .NET testing frameworks with different test platforms.

## MSTest

The MSTest samples demonstrate the same test using two different test platforms:

- [VSTest](mstest/vstest)
- [Microsoft.Testing.Platform](mstest/microsoft-testing-platform)

### VSTest

The VSTest sample uses MSTest with the VSTest platform.

To run the sample from this directory:

```bash
dotnet test mstest/vstest/MSTestVSTest.csproj
```

### Microsoft.Testing.Platform

The Microsoft.Testing.Platform sample uses `MSTest.Sdk` and the MSTest runner based on Microsoft.Testing.Platform.

To run the sample from this directory:

```bash
dotnet test mstest/microsoft-testing-platform/MSTestMTP.csproj
```

Both samples contain the same minimal test so that the differences between the test platform configurations are easy to compare.

Additional testing framework samples can be added in separate directories.
13 changes: 13 additions & 0 deletions test/mstest/microsoft-testing-platform/CalculatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MSTestMTP;

[TestClass]
public sealed class CalculatorTests
{
[TestMethod]
public void Add_TwoNumbers_ReturnsExpectedSum()
{
int result = 2 + 3;

Assert.AreEqual(5, result);
}
}
16 changes: 16 additions & 0 deletions test/mstest/microsoft-testing-platform/MSTestMTP.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="MSTest.Sdk/3.6.4">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>microsoft_testing_platform</RootNamespace>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!--
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
-->
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

</Project>
13 changes: 13 additions & 0 deletions test/mstest/vstest/CalculatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MSTestVSTest;

[TestClass]
public sealed class CalculatorTests
{
[TestMethod]
public void Add_TwoNumbers_ReturnsExpectedSum()
{
int result = 2 + 3;

Assert.AreEqual(5, result);
}
}
19 changes: 19 additions & 0 deletions test/mstest/vstest/MSTestVSTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest" Version="3.6.4" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
Loading