-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathHelpInfoTests.cs
More file actions
168 lines (147 loc) · 7.41 KB
/
HelpInfoTests.cs
File metadata and controls
168 lines (147 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Testing.Platform.Acceptance.IntegrationTests;
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
using Microsoft.Testing.Platform.Helpers;
namespace MSTest.Acceptance.IntegrationTests;
[TestClass]
public class HelpInfoTests : AcceptanceTestBase<HelpInfoTests.TestAssetFixture>
{
private const string AssetName = "HelpInfo";
[TestMethod]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
public async Task Help_WhenMSTestExtensionRegistered_OutputHelpContentOfRegisteredExtension(string tfm)
{
var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--help", cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIs(ExitCodes.Success);
string wildcardMatchPattern = $"""
MSTest v{MSTestVersion} (UTC *) [* - *]
Usage {AssetName}* [option providers] [extension option providers]
Execute a .NET Test Application.
Options:
--config-file
Specifies a testconfig.json file.
--debug
Allows to pause execution in order to attach to the process for debug purposes.
--diagnostic
Enable the diagnostic logging. The default log level is 'Trace'.
The file will be written in the output directory with the name log_[yyMMddHHmmssfff].diag
--diagnostic-file-prefix
Prefix for the log file name that will replace '[log]_.'
--diagnostic-output-directory
Output directory of the diagnostic logging.
If not specified the file will be generated inside the default 'TestResults' directory.
--diagnostic-synchronous-write
Force the built-in file logger to write the log synchronously.
Useful for scenario where you don't want to lose any log (i.e. in case of crash).
Note that this is slowing down the test execution.
--diagnostic-verbosity
Define the level of the verbosity for the --diagnostic.
The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', and 'Critical'.
--exit-on-process-exit
Exit the test process if dependent process exits. PID must be provided.
--filter-uid
Provides a list of test node UIDs to filter by.
--help
Show the command line help.
--ignore-exit-code
Do not report non successful exit value for specific exit codes
(e.g. '--ignore-exit-code 8;9' ignore exit code 8 and 9 and will return 0 in these case)
--info
Display .NET test application information.
--list-tests
List available tests.
--minimum-expected-tests
Specifies the minimum number of tests that are expected to run.
--results-directory
The directory where the test results are going to be placed.
If the specified directory doesn't exist, it's created.
The default is TestResults in the directory that contains the test application.
--timeout
A global test execution timeout.
Takes one argument as string in the format <value>[h|m|s] where 'value' is float.
Extension options:
--filter
Filters tests using the given expression. For more information, see the Filter option details section. For more information and examples on how to use selective unit test filtering, see https://learn.microsoft.com/dotnet/core/testing/selective-unit-tests.
--maximum-failed-tests
Specifies a maximum number of test failures that, when exceeded, will abort the test run.
--no-ansi
Disable outputting ANSI escape characters to screen.
--no-progress
Disable reporting progress to screen.
--output
Output verbosity when reporting tests.
Valid values are 'Normal', 'Detailed'. Default is 'Normal'.
--settings
The path, relative or absolute, to the .runsettings file. For more information and examples on how to configure test run, see https://learn.microsoft.com/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file#the-runsettings-file
--test-parameter
Specify or override a key-value pair parameter. For more information and examples, see https://learn.microsoft.com/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file#testrunparameters
""";
testHostResult.AssertOutputMatchesLines(wildcardMatchPattern);
}
[TestMethod]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
public async Task Info_WhenMSTestExtensionRegistered_OutputInfoContentOfRegisteredExtension(string tfm)
{
var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--info", cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIs(ExitCodes.Success);
string output = $"""
MSTestExtension
Name: MSTest
Version: {MSTestVersion}
Description: MSTest Framework for Microsoft Testing Platform
Options:
--settings
Arity: 1
Hidden: False
Description: The path, relative or absolute, to the .runsettings file. For more information and examples on how to configure test run, see https://learn.microsoft.com/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file#the-runsettings-file
--filter
Arity: 1
Hidden: False
Description: Filters tests using the given expression. For more information, see the Filter option details section. For more information and examples on how to use selective unit test filtering, see https://learn.microsoft.com/dotnet/core/testing/selective-unit-tests.
--test-parameter
Arity: 1..N
Hidden: False
Description: Specify or override a key-value pair parameter. For more information and examples, see https://learn.microsoft.com/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file#testrunparameters
--maximum-failed-tests
Arity: 1
Hidden: False
Description: Specifies a maximum number of test failures that, when exceeded, will abort the test run.
""";
testHostResult.AssertOutputContains(output);
}
public sealed class TestAssetFixture() : TestAssetFixtureBase()
{
public string TargetAssetPath => GetAssetPath(AssetName);
public override (string ID, string Name, string Code) GetAssetsToGenerate() => (AssetName, AssetName,
SourceCode
.PatchTargetFrameworks(TargetFrameworks.All)
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion));
private const string SourceCode = """
#file HelpInfo.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<EnableMSTestRunner>true</EnableMSTestRunner>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" />
</ItemGroup>
</Project>
#file UnitTest1.cs
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class TestClass
{
[TestMethod]
public void Test() {}
}
""";
}
public TestContext TestContext { get; set; }
}