-
Notifications
You must be signed in to change notification settings - Fork 315
/
DifferentTestFrameworkSimpleTests.cs
145 lines (120 loc) · 5.48 KB
/
DifferentTestFrameworkSimpleTests.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
// 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;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests;
/// <summary>
/// The Run Tests using VsTestConsoleWrapper API's
/// </summary>
[TestClass]
public class DifferentTestFrameworkSimpleTests : AcceptanceTestBase
{
private IVsTestConsoleWrapper? _vstestConsoleWrapper;
private RunEventHandler? _runEventHandler;
[MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_runEventHandler))]
private void Setup()
{
_vstestConsoleWrapper = GetVsTestConsoleWrapper();
_runEventHandler = new RunEventHandler();
}
[TestCleanup]
public void Cleanup()
{
_vstestConsoleWrapper?.EndSession();
}
[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
public void RunTestsWithNunitAdapter(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Setup();
var sources = new List<string>
{
GetAssetFullPath("NUTestProject.dll")
};
_vstestConsoleWrapper.RunTests(
sources,
GetDefaultRunSettings(),
_runEventHandler);
var testCase =
_runEventHandler.TestResults.Where(tr => tr.TestCase.DisplayName.Equals("PassTestMethod1"));
// Assert
Assert.AreEqual(2, _runEventHandler.TestResults.Count);
Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed));
Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed));
// Release builds optimize code, hence line numbers are different.
if (IntegrationTestEnvironment.BuildConfiguration.StartsWith("release", StringComparison.OrdinalIgnoreCase))
{
Assert.AreEqual(14, testCase.First().TestCase.LineNumber);
}
else
{
Assert.AreEqual(13, testCase.First().TestCase.LineNumber);
}
}
[TestMethod]
// there are logs in the diagnostic log, it is failing with NullReferenceException because path is null
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
public void RunTestsWithXunitAdapter(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Setup();
string testAssemblyPath = _testEnvironment.GetTestAsset("XUTestProject.dll");
var sources = new List<string> { testAssemblyPath };
var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.XUnit), "*.TestAdapter.dll").ToList();
_vstestConsoleWrapper.InitializeExtensions(new List<string>() { testAdapterPath.First() });
_vstestConsoleWrapper.RunTests(
sources,
GetDefaultRunSettings(),
_runEventHandler);
var testCase =
_runEventHandler.TestResults.Where(tr => tr.TestCase.DisplayName.Equals("xUnitTestProject.Class1.PassTestMethod1"));
// Assert
Assert.AreEqual(2, _runEventHandler.TestResults.Count);
Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed));
Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed));
// Release builds optimize code, hence line numbers are different.
if (IntegrationTestEnvironment.BuildConfiguration.StartsWith("release", StringComparison.OrdinalIgnoreCase))
{
Assert.AreEqual(15, testCase.First().TestCase.LineNumber);
}
else
{
Assert.AreEqual(14, testCase.First().TestCase.LineNumber);
}
}
[TestMethod]
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource]
public void RunTestsWithNonDllAdapter(RunnerInfo runnerInfo)
{
// This used to be test for Chutzpah, but it has long running problem with updating dependencies,
// so we test against our own test framework, to ensure that we can run test files that are not using
// *.dll as extension.
SetTestEnvironment(_testEnvironment, runnerInfo);
Setup();
var jsSource = Path.Combine(_testEnvironment.TestAssetsPath, "test.js");
var jsInTemp = TempDirectory.CopyFile(jsSource);
var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.NonDll), "*.TestAdapter.dll").ToList();
_vstestConsoleWrapper.InitializeExtensions(new List<string>() { testAdapterPath.First() });
_vstestConsoleWrapper.RunTests(
new[] { jsInTemp },
GetDefaultRunSettings(),
_runEventHandler);
var testCase = _runEventHandler.TestResults.Where(tr => tr.TestCase.DisplayName.Equals("TestMethod1"));
// Assert
Assert.AreEqual(1, _runEventHandler.TestResults.Count);
Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed));
Assert.AreEqual(0, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed));
}
}