-
Notifications
You must be signed in to change notification settings - Fork 319
/
ExecutionTests.cs
235 lines (191 loc) · 10.7 KB
/
ExecutionTests.cs
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.TestPlatform.AcceptanceTests
{
using System;
using System.IO;
using System.Threading;
using global::TestPlatform.TestUtilities;
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class ExecutionTests : AcceptanceTestBase
{
[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void RunMultipleTestAssemblies(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject.dll", "SimpleTestProject2.dll").Trim('\"');
this.InvokeVsTestForExecution(assemblyPaths, this.GetTestAdapterPath(), this.FrameworkArgValue, string.Empty);
this.ValidateSummaryStatus(2, 2, 2);
this.ExitCodeEquals(1); // failing tests
}
[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void RunMultipleTestAssembliesWithoutTestAdapterPath(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject.dll").Trim('\"');
var xunitAssemblyPath = this.testEnvironment.TargetFramework.Equals("net451")?
testEnvironment.GetTestAsset("XUTestProject.dll", "net46") :
testEnvironment.GetTestAsset("XUTestProject.dll");
assemblyPaths = string.Concat(assemblyPaths, "\" \"", xunitAssemblyPath);
this.InvokeVsTestForExecution(assemblyPaths, string.Empty, this.FrameworkArgValue, string.Empty);
this.ValidateSummaryStatus(2, 2, 1);
this.ExitCodeEquals(1); // failing tests
}
[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
[DoNotParallelize]
public void RunMultipleTestAssembliesInParallel(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject.dll", "SimpleTestProject2.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, " /Parallel");
arguments = string.Concat(arguments, " /Platform:x86");
string testhostProcessName = string.Empty;
int expectedNumOfProcessCreated = 0;
if (this.IsDesktopTargetFramework())
{
testhostProcessName = "testhost.x86";
expectedNumOfProcessCreated = 2;
}
else
{
testhostProcessName = "dotnet";
if (this.IsDesktopRunner())
{
expectedNumOfProcessCreated = 2;
}
else
{
// Include launcher dotnet.exe
expectedNumOfProcessCreated = 3;
}
}
var cts = new CancellationTokenSource();
var numOfProcessCreatedTask = NumberOfProcessLaunchedUtility.NumberOfProcessCreated(
cts,
testhostProcessName);
this.InvokeVsTest(arguments);
cts.Cancel();
Assert.AreEqual(
expectedNumOfProcessCreated,
numOfProcessCreatedTask.Result,
$"Number of {testhostProcessName} process created, expected: {expectedNumOfProcessCreated} actual: {numOfProcessCreatedTask.Result}");
this.ValidateSummaryStatus(2, 2, 2);
this.ExitCodeEquals(1); // failing tests
}
[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void TestSessionTimeOutTests(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject3.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, " /TestCaseFilter:TestSessionTimeoutTest");
// set TestSessionTimeOut = 7 sec
arguments = string.Concat(arguments, " -- RunConfiguration.TestSessionTimeout=7000");
this.InvokeVsTest(arguments);
this.ExitCodeEquals(1);
this.StdErrorContains("Test Run Aborted.");
this.StdErrorContains("Aborting test run: test run timeout of 7000 milliseconds exceeded.");
this.StdOutputDoesNotContains("Total tests: 6");
}
[TestMethod]
[NetCoreTargetFrameworkDataSource]
public void TestPlatformShouldBeCompatibleWithOldTestHost(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var assemblyPaths = this.BuildMultipleAssemblyPath("SampleProjectWithOldTestHost.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);
this.ExitCodeEquals(0);
}
[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void WorkingDirectoryIsSourceDirectory(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject3.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, " /tests:WorkingDirectoryTest");
this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);
this.ExitCodeEquals(0);
}
[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
public void StackOverflowExceptionShouldBeLoggedToConsoleAndDiagLogFile(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
if (IntegrationTestEnvironment.BuildConfiguration.Equals("release", StringComparison.OrdinalIgnoreCase))
{
// On release, x64 builds, recursive calls may be replaced with loops (tail call optimization)
Assert.Inconclusive("On StackOverflowException testhost not exited in release configuration.");
return;
}
var diagLogFilePath = Path.Combine(Path.GetTempPath(), $"std_error_log_{Guid.NewGuid()}.txt");
File.Delete(diagLogFilePath);
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject3.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, " /testcasefilter:ExitWithStackoverFlow");
arguments = string.Concat(arguments, $" /diag:{diagLogFilePath}");
this.InvokeVsTest(arguments);
var errorMessage = "Process is terminated due to StackOverflowException.";
if (runnerInfo.TargetFramework.StartsWith("netcoreapp2."))
{
errorMessage = "Process is terminating due to StackOverflowException.";
}
this.ExitCodeEquals(1);
FileAssert.Contains(diagLogFilePath, errorMessage);
this.StdErrorContains(errorMessage);
File.Delete(diagLogFilePath);
}
[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
public void UnhandleExceptionExceptionShouldBeLoggedToDiagLogFile(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var diagLogFilePath = Path.Combine(Path.GetTempPath(), $"std_error_log_{Guid.NewGuid()}.txt");
File.Delete(diagLogFilePath);
var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject3.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, " /testcasefilter:ExitwithUnhandleException");
arguments = string.Concat(arguments, $" /diag:{diagLogFilePath}");
this.InvokeVsTest(arguments);
var errorFirstLine = "Test host standard error line: Unhandled Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object.";
FileAssert.Contains(diagLogFilePath, errorFirstLine);
File.Delete(diagLogFilePath);
}
[TestMethod]
[NetFullTargetFrameworkDataSource]
public void IncompatibleSourcesWarningShouldBeDisplayedInTheConsole(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var expectedWarningContains = @"Following DLL(s) do not match framework/platform settings. SimpleTestProject3.dll is built for Framework .NETFramework,Version=v4.5.1 and Platform X64";
var assemblyPaths =
this.BuildMultipleAssemblyPath("SimpleTestProject3.dll", "SimpleTestProjectx86.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, " /testcasefilter:PassingTestx86");
this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);
this.ExitCodeEquals(0);
// When both x64 & x86 DLL is passed x64 dll will be ignored.
this.StdOutputContains(expectedWarningContains);
}
}
}