Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8a0cb37

Browse files
authoredNov 30, 2024··
Add a MSTest sample with a program.cs (#4201)
1 parent 5f655be commit 8a0cb37

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35507.96 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTestProjectWithExplicitMain", "MSTestProjectWithExplicitMain\MSTestProjectWithExplicitMain.csproj", "{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {68CE81DD-68F6-49B0-87AF-DC6223F45845}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<EnableMSTestRunner>true</EnableMSTestRunner>
9+
<OutputType>Exe</OutputType>
10+
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
11+
<!--
12+
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
13+
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
14+
-->
15+
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
16+
17+
<GenerateTestingPlatformEntryPoint>false</GenerateTestingPlatformEntryPoint>
18+
</PropertyGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
22+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.12.6" />
23+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.4.0" />
24+
<PackageReference Include="MSTest" Version="3.6.1" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
29+
</ItemGroup>
30+
31+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Reflection;
5+
6+
using Microsoft.Testing.Extensions;
7+
using Microsoft.Testing.Platform.Builder;
8+
9+
// Create the test application builder
10+
ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
11+
12+
// Register the testing framework
13+
testApplicationBuilder.AddMSTest(() => new[] { Assembly.GetExecutingAssembly() });
14+
15+
// Register Code Coverage extension
16+
testApplicationBuilder.AddCodeCoverageProvider();
17+
18+
// Register TRX report extension
19+
testApplicationBuilder.AddTrxReportProvider();
20+
21+
// Register Telemetry extension
22+
testApplicationBuilder.AddAppInsightsTelemetryProvider();
23+
24+
// Alternatively, instead of registering everything manually, I could rely on the MSBuild hooks and use
25+
// testApplicationBuilder.AddSelfRegisteredExtensions(args);
26+
// This is what is called by the generated entry point
27+
28+
// In addition to be using each extension helper method, we can directly register extensions to each of
29+
// the extensibility area. For now, the following 3 are exposed:
30+
// testApplicationBuilder.CommandLine
31+
// testApplicationBuilder.TestHost
32+
// testApplicationBuilder.TestHostControllers
33+
// but the goal is to also expose all these areas: https://github.com/microsoft/testfx/blob/main/src/Platform/Microsoft.Testing.Platform/Builder/TestApplicationBuilder.cs#L57-L69
34+
35+
// NOTE that registering an extension is not enough and each extension has some activation criteria,
36+
// most of the time the presence of a command line option but it could be anything (including nothing).
37+
38+
// Build the test app
39+
using ITestApplication testApplication = await testApplicationBuilder.BuildAsync();
40+
41+
// Run the test app
42+
return await testApplication.RunAsync();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace MSTestProjectWithExplicitMain;
5+
6+
[TestClass]
7+
public sealed class Test1
8+
{
9+
[TestMethod]
10+
public void TestMethod1()
11+
{
12+
}
13+
}

0 commit comments

Comments
 (0)
Please sign in to comment.