-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathConfigurationMSTestSettingsTests.cs
More file actions
182 lines (158 loc) · 5.35 KB
/
ConfigurationMSTestSettingsTests.cs
File metadata and controls
182 lines (158 loc) · 5.35 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// 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 sealed class ConfigurationMSTestSettingsTests : AcceptanceTestBase<ConfigurationMSTestSettingsTests.TestAssetFixture>
{
public TestContext TestContext { get; set; }
[TestMethod]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
public async Task TestConfigJson_AndRunSettingsHasMstest_Throws(string tfm)
{
var testHost = TestHost.LocateFrom(AssetFixture.ProjectPathWithMSTestRunSettings, TestAssetFixture.ProjectNameWithMSTestRunSettings, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings", cancellationToken: TestContext.CancellationToken);
// Assert
testHostResult.AssertExitCodeIsNot(ExitCodes.Success);
testHostResult.AssertStandardErrorContains("Both '.runsettings' and '.testconfig.json' files have been detected. Please select only one of these test configuration files.");
}
public sealed class TestAssetFixture() : TestAssetFixtureBase()
{
public const string ProjectNameWithMSTestRunSettings = "ConfigurationMSTestSettings";
public string ProjectPathWithMSTestRunSettings => GetAssetPath(ProjectNameWithMSTestRunSettings);
public override (string ID, string Name, string Code) GetAssetsToGenerate() => (ProjectNameWithMSTestRunSettings, ProjectNameWithMSTestRunSettings,
SourceCode
.PatchTargetFrameworks(TargetFrameworks.All)
.PatchCodeWithReplace("$ProjectName$", ProjectNameWithMSTestRunSettings)
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)
.PatchCodeWithReplace("$AppendSettings$", MSTestSettings));
private const string MSTestSettings = """
<mstest>
</mstest>
""";
private const string SourceCode = """
#file $ProjectName$.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<EnableMSTestRunner>true</EnableMSTestRunner>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
<LangVersion>Preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" />
</ItemGroup>
<ItemGroup>
<None Update="*.runsettings">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="*.testconfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="dummyconfigfile_map.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="dummyconfigfile_doNotMap.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
#file my.runsettings
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<CollectSourceInformation>true</CollectSourceInformation>
<EXECUTIONTHREADAPARTMENTSTATE>STA</EXECUTIONTHREADAPARTMENTSTATE>
<DisableAppDomain>true</DisableAppDomain>
</RunConfiguration>
$AppendSettings$
</RunSettings>
#file dummyconfigfile_map.json
{
"mstest": {
"execution": {
"mapInconclusiveToFailed": true,
},
}
}
#file dummyconfigfile_doNotMap.json
{
"mstest": {
"execution": {
"mapInconclusiveToFailed": false,
},
}
}
#file $ProjectName$.testconfig.json
{
"mstest": {
"timeout": {
"assemblyInitialize": 300000,
"assemblyCleanup": 300000,
"classInitialize": 200000,
"classCleanup": 200000,
"testInitialize": 100000,
"testCleanup": 100000,
"test": 60000,
"useCooperativeCancellation": true
},
"parallelism": {
"enabled": true,
"workers": 4,
"scope": "class"
},
"execution": {
"collectSourceInformation": true,
"executionApartmentState": "MTA",
"disableAppDomain": false,
"mapInconclusiveToFailed": true,
"mapNotRunnableToFailed": true,
"treatDiscoveryWarningsAsErrors": true,
"considerEmptyDataSourceAsInconclusive": true
},
"deployment": {
"enabled": true,
"deployTestSourceDependencies": false,
"deleteDeploymentDirectoryAfterTestRunIsComplete": true
},
"assemblyResolution": [
{
"path": "C:\\project\\dependencies",
"includeSubDirectories": "true"
},
{
"path": "C:\\project\\libs",
"includeSubDirectories": "true"
},
{
"path": "C:\\project\\plugins",
"includeSubDirectories": "true"
}
]
}
}
#file UnitTest1.cs
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod()
{
}
[TestMethod]
public void TestWithConfigFromCommandLine()
{
if (Environment.GetEnvironmentVariable("TestWithConfigFromCommandLine") == "true")
{
Assert.Inconclusive("Inconclusive TestWithConfigFromCommandLine");
}
}
}
""";
}
}