Skip to content

Commit b6cdf7d

Browse files
authored
Downgrade externals - tests for test platform nuget (#2649)
* Downgrade externals - tests for test platform nuget * uncomment * Add back interop for signing * Downgrade even more * Fixing tests
1 parent 7207f7e commit b6cdf7d

File tree

7 files changed

+137
-35
lines changed

7 files changed

+137
-35
lines changed

scripts/build/TestPlatform.Dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<NuGetFrameworksVersion>5.0.0</NuGetFrameworksVersion>
3232
<JsonNetVersion>9.0.1</JsonNetVersion>
3333
<MoqVersion>4.7.63</MoqVersion>
34-
<TestPlatformExternalsVersion>16.9.0-preview-4243816</TestPlatformExternalsVersion>
34+
<TestPlatformExternalsVersion>16.9.0-preview-4189539</TestPlatformExternalsVersion>
3535
<CodeCoverageExternalsVersion>16.9.0-beta.20570.2</CodeCoverageExternalsVersion>
3636
<MicrosoftFakesVersion>16.8.0-beta.20420.2</MicrosoftFakesVersion>
3737

scripts/verify-nupkgs.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Verify-Nuget-Packages($packageDirectory, $version)
1515
$expectedNumOfFiles = @{
1616
"Microsoft.CodeCoverage" = 44;
1717
"Microsoft.NET.Test.Sdk" = 18;
18-
"Microsoft.TestPlatform" = 486;
18+
"Microsoft.TestPlatform" = 487;
1919
"Microsoft.TestPlatform.Build" = 19;
2020
"Microsoft.TestPlatform.CLI" = 353;
2121
"Microsoft.TestPlatform.Extensions.TrxLogger" = 33;

src/package/nuspec/Microsoft.TestPlatform.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
<file src="net451\$Runtime$\Extensions\Microsoft.VisualStudio.TestTools.DataCollection.MediaRecorder.Model.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Microsoft.VisualStudio.TestTools.DataCollection.MediaRecorder.Model.dll" />
268268
<file src="net451\$Runtime$\Extensions\Microsoft.VisualStudio.TestTools.DataCollection.VideoRecorderCollector.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Microsoft.VisualStudio.TestTools.DataCollection.VideoRecorderCollector.dll" />
269269
<file src="net451\$Runtime$\Extensions\Microsoft.VisualStudio.TraceDataCollector.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Microsoft.VisualStudio.TraceDataCollector.dll" />
270+
<file src="net451\$Runtime$\Extensions\Microsoft.VisualStudio.Coverage.Interop.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Microsoft.VisualStudio.Coverage.Interop.dll" />
270271
<file src="net451\$Runtime$\Extensions\VideoRecorder\VSTestVideoRecorder.exe" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\VideoRecorder\VSTestVideoRecorder.exe" />
271272
<file src="net451\$Runtime$\Extensions\Cpp\dbghelp.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Cpp\dbghelp.dll" />
272273
<file src="net451\$Runtime$\Extensions\Cpp\Microsoft.VisualStudio.TestTools.CppUnitTestFramework.Discoverer.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Cpp\Microsoft.VisualStudio.TestTools.CppUnitTestFramework.Discoverer.dll" />

src/package/sign/sign.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@
130130
<AssembliesToSign Include="$(ArtifactsDirectory)QTDCAgent32.exe" />
131131

132132
<!-- DataCollector related dlls -->
133-
<AssembliesToSign Include="$(ArtifactsDirectory)Microsoft.IntelliTrace.Core.dll" />
133+
<AssembliesToSign Include="$(ArtifactsDirectory)Microsoft.IntelliTrace.Core.dll" />
134134
<AssembliesToSign Include="$(ArtifactsDirectory)Microsoft.VisualStudio.Coverage.CoreLib.Net.dll" />
135135
<AssembliesToSign Include="$(ArtifactsDirectory)Microsoft.VisualStudio.Diagnostics.Utilities.dll" />
136136
<AssembliesToSign Include="$(ArtifactsDirectory)Microsoft.VisualStudio.Enterprise.AspNetHelper.dll" />
137137
<AssembliesToSign Include="$(ArtifactsDirectory)Microsoft.VisualStudio.ArchitectureTools.PEReader.dll" />
138138
<AssembliesToSign Include="$(ArtifactsDirectory)Extensions\Microsoft.VisualStudio.TraceDataCollector.dll" />
139+
<AssembliesToSign Include="$(ArtifactsDirectory)Extensions\Microsoft.VisualStudio.Coverage.Interop.dll" />
139140

140141
<!-- CUIT related dlls -->
141142
<AssembliesToSign Include="$(ArtifactsDirectory)Microsoft.VisualStudio.Diagnostics.Measurement.dll" />

test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageAcceptanceTestBase.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,37 @@ protected void AssertCoverage(XmlNode node, double expectedCoverage)
7575
Console.WriteLine($"Checking coverage for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Result: {coverage}");
7676
Assert.IsTrue(coverage > expectedCoverage, $"Coverage check failed for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Found: {coverage}");
7777
}
78+
79+
protected static string GetCoverageFileNameFromTrx(string trxFilePath, string resultsDirectory)
80+
{
81+
Assert.IsTrue(File.Exists(trxFilePath), "Trx file not found: {0}", trxFilePath);
82+
XmlDocument doc = new XmlDocument();
83+
using (var trxStream = new FileStream(trxFilePath, FileMode.Open, FileAccess.Read))
84+
{
85+
doc.Load(trxStream);
86+
var deploymentElements = doc.GetElementsByTagName("Deployment");
87+
Assert.IsTrue(deploymentElements.Count == 1,
88+
"None or more than one Deployment tags found in trx file:{0}", trxFilePath);
89+
var deploymentDir = deploymentElements[0].Attributes.GetNamedItem("runDeploymentRoot")?.Value;
90+
Assert.IsTrue(string.IsNullOrEmpty(deploymentDir) == false,
91+
"runDeploymentRoot attribute not found in trx file:{0}", trxFilePath);
92+
var collectors = doc.GetElementsByTagName("Collector");
93+
94+
string fileName = string.Empty;
95+
for (int i = 0; i < collectors.Count; i++)
96+
{
97+
if (string.Equals(collectors[i].Attributes.GetNamedItem("collectorDisplayName").Value,
98+
"Code Coverage", StringComparison.OrdinalIgnoreCase))
99+
{
100+
fileName = collectors[i].FirstChild?.FirstChild?.FirstChild?.Attributes.GetNamedItem("href")
101+
?.Value;
102+
}
103+
}
104+
105+
Assert.IsTrue(string.IsNullOrEmpty(fileName) == false, "Coverage file name not found in trx file: {0}",
106+
trxFilePath);
107+
return Path.Combine(resultsDirectory, deploymentDir, "In", fileName);
108+
}
109+
}
78110
}
79111
}

test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -283,37 +283,5 @@ private void AssertSourceFileName(XmlNode module)
283283

284284
Assert.IsTrue(found);
285285
}
286-
287-
private static string GetCoverageFileNameFromTrx(string trxFilePath, string resultsDirectory)
288-
{
289-
Assert.IsTrue(File.Exists(trxFilePath), "Trx file not found: {0}", trxFilePath);
290-
XmlDocument doc = new XmlDocument();
291-
using (var trxStream = new FileStream(trxFilePath, FileMode.Open, FileAccess.Read))
292-
{
293-
doc.Load(trxStream);
294-
var deploymentElements = doc.GetElementsByTagName("Deployment");
295-
Assert.IsTrue(deploymentElements.Count == 1,
296-
"None or more than one Deployment tags found in trx file:{0}", trxFilePath);
297-
var deploymentDir = deploymentElements[0].Attributes.GetNamedItem("runDeploymentRoot")?.Value;
298-
Assert.IsTrue(string.IsNullOrEmpty(deploymentDir) == false,
299-
"runDeploymentRoot attribute not found in trx file:{0}", trxFilePath);
300-
var collectors = doc.GetElementsByTagName("Collector");
301-
302-
string fileName = string.Empty;
303-
for (int i = 0; i < collectors.Count; i++)
304-
{
305-
if (string.Equals(collectors[i].Attributes.GetNamedItem("collectorDisplayName").Value,
306-
"Code Coverage", StringComparison.OrdinalIgnoreCase))
307-
{
308-
fileName = collectors[i].FirstChild?.FirstChild?.FirstChild?.Attributes.GetNamedItem("href")
309-
?.Value;
310-
}
311-
}
312-
313-
Assert.IsTrue(string.IsNullOrEmpty(fileName) == false, "Coverage file name not found in trx file: {0}",
314-
trxFilePath);
315-
return Path.Combine(resultsDirectory, deploymentDir, "In", fileName);
316-
}
317-
}
318286
}
319287
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.TestPlatform.AcceptanceTests
5+
{
6+
using System;
7+
using System.IO;
8+
using System.IO.Compression;
9+
using System.Linq;
10+
11+
using Microsoft.TestPlatform.TestUtilities;
12+
using Microsoft.VisualStudio.TestTools.UnitTesting;
13+
14+
[TestClass]
15+
public class TestPlatformNugetPackageTests : CodeCoverageAcceptanceTestBase
16+
{
17+
private static string nugetPackageFolder;
18+
private string resultsDirectory;
19+
20+
[ClassInitialize]
21+
public static void ClassInit(TestContext testContext)
22+
{
23+
var packageLocation = Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, "artifacts", IntegrationTestEnvironment.BuildConfiguration, "packages");
24+
var nugetPackage = Directory.EnumerateFiles(packageLocation, "Microsoft.TestPlatform.*.nupkg").OrderBy(a => a).FirstOrDefault();
25+
nugetPackageFolder = Path.Combine(packageLocation, Path.GetFileNameWithoutExtension(nugetPackage));
26+
ZipFile.ExtractToDirectory(nugetPackage, nugetPackageFolder);
27+
28+
Directory.Move(Path.Combine(nugetPackageFolder, "tools", "net451", "Team%20Tools"), Path.Combine(nugetPackageFolder, "tools", "net451", "Team Tools"));
29+
Directory.Move(Path.Combine(nugetPackageFolder, "tools", "net451", "Team Tools", "Dynamic%20Code%20Coverage%20Tools"), Path.Combine(nugetPackageFolder, "tools", "net451", "Team Tools", "Dynamic Code Coverage Tools"));
30+
}
31+
32+
[ClassCleanup]
33+
public static void ClassCleanup()
34+
{
35+
Directory.Delete(nugetPackageFolder, true);
36+
}
37+
38+
[TestInitialize]
39+
public void SetUp()
40+
{
41+
this.resultsDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
42+
}
43+
44+
[TestCleanup]
45+
public void CleanUp()
46+
{
47+
Directory.Delete(resultsDirectory, true);
48+
}
49+
50+
[TestMethod]
51+
[NetFullTargetFrameworkDataSource(useCoreRunner: false)]
52+
[NetCoreTargetFrameworkDataSource(useCoreRunner: false)]
53+
public void RunMultipleTestAssembliesWithCodeCoverage(RunnerInfo runnerInfo)
54+
{
55+
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
56+
57+
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject.dll", "SimpleTestProject2.dll").Trim('\"');
58+
59+
var arguments = CreateCodeCoverageArguments(runnerInfo, assemblyPaths, out var trxFilePath);
60+
this.InvokeVsTest(arguments);
61+
62+
this.ExitCodeEquals(1); // failing tests
63+
64+
var actualCoverageFile = CodeCoverageTests.GetCoverageFileNameFromTrx(trxFilePath, resultsDirectory);
65+
Console.WriteLine($@"Coverage file: {actualCoverageFile} Results directory: {resultsDirectory} trxfile: {trxFilePath}");
66+
Assert.IsTrue(File.Exists(actualCoverageFile), "Coverage file not found: {0}", actualCoverageFile);
67+
}
68+
69+
public override string GetConsoleRunnerPath()
70+
{
71+
string consoleRunnerPath = string.Empty;
72+
73+
if (this.IsDesktopRunner())
74+
{
75+
consoleRunnerPath = Path.Combine(nugetPackageFolder, "tools", "net451", "Common7", "IDE", "Extensions", "TestPlatform", "vstest.console.exe");
76+
}
77+
78+
Assert.IsTrue(File.Exists(consoleRunnerPath), "GetConsoleRunnerPath: Path not found: {0}", consoleRunnerPath);
79+
return consoleRunnerPath;
80+
}
81+
82+
private string CreateCodeCoverageArguments(
83+
RunnerInfo runnerInfo,
84+
string assemblyPaths,
85+
out string trxFilePath)
86+
{
87+
string diagFileName = Path.Combine(this.resultsDirectory, "diaglog.txt");
88+
89+
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty,
90+
this.FrameworkArgValue, runnerInfo.InIsolationValue);
91+
92+
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDirectory}", $" /Diag:{diagFileName}", $" /EnableCodeCoverage");
93+
94+
trxFilePath = Path.Combine(this.resultsDirectory, Guid.NewGuid() + ".trx");
95+
arguments = string.Concat(arguments, " /logger:trx;logfilename=" + trxFilePath);
96+
97+
return arguments;
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)