Skip to content

Commit 684633e

Browse files
committed
Fix test
1 parent 0d2a4cd commit 684633e

File tree

5 files changed

+29
-37
lines changed

5 files changed

+29
-37
lines changed

test/E2ETests/Automation.CLI/CLITestBase.common.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected string GetTestAdapterPath()
7979
/// <param name="settingsXml">RunSettings provided for discovery/execution</param>
8080
/// <param name="testAdapterPath">Full path to TestAdapter.</param>
8181
/// <returns>RunSettingXml as string</returns>
82-
protected string GetRunSettingXml(string settingsXml, string testAdapterPath)
82+
protected string GetRunSettingXml(string settingsXml, string testAdapterPath, string targetFramework = "")
8383
{
8484
if (string.IsNullOrEmpty(settingsXml))
8585
{
@@ -93,7 +93,7 @@ protected string GetRunSettingXml(string settingsXml, string testAdapterPath)
9393
}
9494

9595
XmlElement root = doc.DocumentElement;
96-
RunConfiguration runConfiguration = new(testAdapterPath);
96+
RunConfiguration runConfiguration = new(Path.Combine(testAdapterPath, targetFramework));
9797
XmlElement runConfigElement = runConfiguration.ToXml();
9898
if (root[runConfiguration.SettingsName] == null)
9999
{

test/E2ETests/Automation.CLI/CLITestBase.e2e.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public partial class CLITestBase : TestContainer
2222

2323
public CLITestBase()
2424
{
25-
Environment.CurrentDirectory = @"C:\Users\enjieid\source\repos\testfx";
2625
s_vsTestConsoleWrapper = new VsTestConsoleWrapper(GetConsoleRunnerPath());
2726
s_vsTestConsoleWrapper.StartSession();
2827
}
@@ -48,12 +47,12 @@ public void InvokeVsTestForDiscovery(string[] sources, string runSettings = "")
4847
/// <param name="sources">List of test assemblies.</param>
4948
/// <param name="runSettings">Run settings for execution.</param>
5049
/// <param name="testCaseFilter">Test Case filter for execution.</param>
51-
public void InvokeVsTestForExecution(string[] sources, string runSettings = "", string testCaseFilter = null)
50+
public void InvokeVsTestForExecution(string[] sources, string runSettings = "", string testCaseFilter = null, string targetFramework = "")
5251
{
5352
ExpandTestSourcePaths(sources);
5453

5554
_runEventsHandler = new RunEventsHandler();
56-
string runSettingXml = GetRunSettingXml(runSettings, GetTestAdapterPath());
55+
string runSettingXml = GetRunSettingXml(runSettings, GetTestAdapterPath(), targetFramework);
5756

5857
s_vsTestConsoleWrapper.RunTests(sources, runSettingXml, new TestPlatformOptions { TestCaseFilter = testCaseFilter }, _runEventsHandler);
5958
if (_runEventsHandler.Errors.Any())
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System;
5-
using System.Collections.Generic;
64
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
95

106
using Microsoft.MSTestV2.CLIAutomation;
117

@@ -16,12 +12,12 @@ public class SuiteLifeCycleTests : CLITestBase
1612

1713
public void ValidateTestRunLifecycle_net6()
1814
{
19-
ValidateTestRunLifecycle("net462");
15+
ValidateTestRunLifecycle("net6.0");
2016
}
2117

2218
private void ValidateTestRunLifecycle(string targetFramework)
2319
{
24-
InvokeVsTestForExecution(new[] { targetFramework + "\\" + Assembly });
20+
InvokeVsTestForExecution(new[] { targetFramework + "\\" + Assembly }, targetFramework: targetFramework);
2521
Verify(_runEventsHandler.PassedTests.Count == 1);
2622

2723
var testMethod = _runEventsHandler.PassedTests.Single();
@@ -30,28 +26,28 @@ private void ValidateTestRunLifecycle(string targetFramework)
3026
{
3127
Verify(testMethod.Messages.Single().Text.Contains(
3228
"""
33-
ClassInitialize was called
34-
Ctor was called
35-
TestInitialize was called
36-
TestMethod was called
37-
TestCleanup was called
38-
Dispose was called
39-
ClassCleanup was called
40-
"""));
29+
ClassInitialize was called
30+
Ctor was called
31+
TestInitialize was called
32+
TestMethod was called
33+
TestCleanup was called
34+
Dispose was called
35+
ClassCleanup was called
36+
"""));
4137
}
4238
else
4339
{
4440
Verify(testMethod.Messages.Single().Text.Contains(
4541
"""
46-
ClassInitialize was called
47-
Ctor was called
48-
TestInitialize was called
49-
TestMethod was called
50-
TestCleanup was called
51-
DisposeAsync was called
52-
Dispose was called
53-
ClassCleanup was called
54-
"""));
42+
ClassInitialize was called
43+
Ctor was called
44+
TestInitialize was called
45+
TestMethod was called
46+
TestCleanup was called
47+
DisposeAsync was called
48+
Dispose was called
49+
ClassCleanup was called
50+
"""));
5551
}
5652
}
5753
}

test/E2ETests/TestAssets/SuiteLifeCycleTestProject/SuiteLifeCycleTestClass.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
using System;
55
using System.Diagnostics;
6-
using System.Threading;
7-
using System.Threading.Tasks;
6+
#if NET6_0_OR_GREATER
7+
using System.Threading.Tasks;
8+
#endif
89

910
using Microsoft.VisualStudio.TestTools.UnitTesting;
1011

@@ -41,8 +42,6 @@ public void TestInitialize()
4142
[TestMethod]
4243
public void TestMethod()
4344
{
44-
Debugger.Launch();
45-
Debugger.Break();
4645
TestContext.WriteLine("TestMethod was called");
4746
}
4847

@@ -62,13 +61,12 @@ public ValueTask DisposeAsync()
6261
{
6362
TestContext.WriteLine("DisposeAsync was called");
6463
return ValueTask.CompletedTask;
65-
6664
}
6765
#endif
6866

6967
[ClassCleanup]
70-
public void ClassCleanup()
68+
public static void ClassCleanup()
7169
{
72-
TestContext.WriteLine("ClassCleanup was called");
70+
s_testContext.WriteLine("ClassCleanup was called");
7371
}
7472
}

test/E2ETests/TestAssets/SuiteLifeCycleTestProject/SuiteLifeCycleTestProject.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<ProjectReference Include="$(RepoRoot)\src\TestFramework\TestFramework.Extensions\TestFramework.Extensions.csproj" />
15-
<ProjectReference Include="$(RepoRoot)\src\TestFramework\TestFramework\TestFramework.csproj" />
14+
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj" />
1615
</ItemGroup>
1716

1817
</Project>

0 commit comments

Comments
 (0)