-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a MSTest sample with a program.cs (#4201)
- Loading branch information
1 parent
5f655be
commit 8a0cb37
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
samples/public/mstest-runner/MSTestProjectWithExplicitMain/MSTestProjectWithExplicitMain.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.13.35507.96 d17.13 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTestProjectWithExplicitMain", "MSTestProjectWithExplicitMain\MSTestProjectWithExplicitMain.csproj", "{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3F00FD7B-D9E6-42C6-8607-3186BFBD4A0F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {68CE81DD-68F6-49B0-87AF-DC6223F45845} | ||
EndGlobalSection | ||
EndGlobal |
31 changes: 31 additions & 0 deletions
31
...rojectWithExplicitMain/MSTestProjectWithExplicitMain/MSTestProjectWithExplicitMain.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<EnableMSTestRunner>true</EnableMSTestRunner> | ||
<OutputType>Exe</OutputType> | ||
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport> | ||
<!-- | ||
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> | ||
|
||
<GenerateTestingPlatformEntryPoint>false</GenerateTestingPlatformEntryPoint> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.12.6" /> | ||
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.4.0" /> | ||
<PackageReference Include="MSTest" Version="3.6.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
4 changes: 4 additions & 0 deletions
4
...test-runner/MSTestProjectWithExplicitMain/MSTestProjectWithExplicitMain/MSTestSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] |
42 changes: 42 additions & 0 deletions
42
...blic/mstest-runner/MSTestProjectWithExplicitMain/MSTestProjectWithExplicitMain/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Reflection; | ||
|
||
using Microsoft.Testing.Extensions; | ||
using Microsoft.Testing.Platform.Builder; | ||
|
||
// Create the test application builder | ||
ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args); | ||
|
||
// Register the testing framework | ||
testApplicationBuilder.AddMSTest(() => new[] { Assembly.GetExecutingAssembly() }); | ||
|
||
// Register Code Coverage extension | ||
testApplicationBuilder.AddCodeCoverageProvider(); | ||
|
||
// Register TRX report extension | ||
testApplicationBuilder.AddTrxReportProvider(); | ||
|
||
// Register Telemetry extension | ||
testApplicationBuilder.AddAppInsightsTelemetryProvider(); | ||
|
||
// Alternatively, instead of registering everything manually, I could rely on the MSBuild hooks and use | ||
// testApplicationBuilder.AddSelfRegisteredExtensions(args); | ||
// This is what is called by the generated entry point | ||
|
||
// In addition to be using each extension helper method, we can directly register extensions to each of | ||
// the extensibility area. For now, the following 3 are exposed: | ||
// testApplicationBuilder.CommandLine | ||
// testApplicationBuilder.TestHost | ||
// testApplicationBuilder.TestHostControllers | ||
// 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 | ||
|
||
// NOTE that registering an extension is not enough and each extension has some activation criteria, | ||
// most of the time the presence of a command line option but it could be anything (including nothing). | ||
|
||
// Build the test app | ||
using ITestApplication testApplication = await testApplicationBuilder.BuildAsync(); | ||
|
||
// Run the test app | ||
return await testApplication.RunAsync(); |
13 changes: 13 additions & 0 deletions
13
...public/mstest-runner/MSTestProjectWithExplicitMain/MSTestProjectWithExplicitMain/Test1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace MSTestProjectWithExplicitMain; | ||
|
||
[TestClass] | ||
public sealed class Test1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
} | ||
} |