Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade externals - tests for test platform nuget #2649

Merged
merged 5 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/build/TestPlatform.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<NuGetFrameworksVersion>5.0.0</NuGetFrameworksVersion>
<JsonNetVersion>9.0.1</JsonNetVersion>
<MoqVersion>4.7.63</MoqVersion>
<TestPlatformExternalsVersion>16.9.0-preview-4243816</TestPlatformExternalsVersion>
<TestPlatformExternalsVersion>16.9.0-preview-4224421</TestPlatformExternalsVersion>
<CodeCoverageExternalsVersion>16.9.0-beta.20570.2</CodeCoverageExternalsVersion>
<MicrosoftFakesVersion>16.8.0-beta.20420.2</MicrosoftFakesVersion>

Expand Down
2 changes: 1 addition & 1 deletion scripts/verify-nupkgs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Verify-Nuget-Packages($packageDirectory, $version)
$expectedNumOfFiles = @{
"Microsoft.CodeCoverage" = 44;
"Microsoft.NET.Test.Sdk" = 18;
"Microsoft.TestPlatform" = 486;
"Microsoft.TestPlatform" = 487;
"Microsoft.TestPlatform.Build" = 19;
"Microsoft.TestPlatform.CLI" = 353;
"Microsoft.TestPlatform.Extensions.TrxLogger" = 33;
Expand Down
1 change: 1 addition & 0 deletions src/package/nuspec/Microsoft.TestPlatform.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
<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" />
<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" />
<file src="net451\$Runtime$\Extensions\Microsoft.VisualStudio.TraceDataCollector.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Microsoft.VisualStudio.TraceDataCollector.dll" />
<file src="net451\$Runtime$\Extensions\Microsoft.VisualStudio.Coverage.Interop.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Microsoft.VisualStudio.Coverage.Interop.dll" />
<file src="net451\$Runtime$\Extensions\VideoRecorder\VSTestVideoRecorder.exe" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\VideoRecorder\VSTestVideoRecorder.exe" />
<file src="net451\$Runtime$\Extensions\Cpp\dbghelp.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Extensions\Cpp\dbghelp.dll" />
<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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,37 @@ protected void AssertCoverage(XmlNode node, double expectedCoverage)
Console.WriteLine($"Checking coverage for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Result: {coverage}");
Assert.IsTrue(coverage > expectedCoverage, $"Coverage check failed for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Found: {coverage}");
}

protected static string GetCoverageFileNameFromTrx(string trxFilePath, string resultsDirectory)
{
Assert.IsTrue(File.Exists(trxFilePath), "Trx file not found: {0}", trxFilePath);
XmlDocument doc = new XmlDocument();
using (var trxStream = new FileStream(trxFilePath, FileMode.Open, FileAccess.Read))
{
doc.Load(trxStream);
var deploymentElements = doc.GetElementsByTagName("Deployment");
Assert.IsTrue(deploymentElements.Count == 1,
"None or more than one Deployment tags found in trx file:{0}", trxFilePath);
var deploymentDir = deploymentElements[0].Attributes.GetNamedItem("runDeploymentRoot")?.Value;
Assert.IsTrue(string.IsNullOrEmpty(deploymentDir) == false,
"runDeploymentRoot attribute not found in trx file:{0}", trxFilePath);
var collectors = doc.GetElementsByTagName("Collector");

string fileName = string.Empty;
for (int i = 0; i < collectors.Count; i++)
{
if (string.Equals(collectors[i].Attributes.GetNamedItem("collectorDisplayName").Value,
"Code Coverage", StringComparison.OrdinalIgnoreCase))
{
fileName = collectors[i].FirstChild?.FirstChild?.FirstChild?.Attributes.GetNamedItem("href")
?.Value;
}
}

Assert.IsTrue(string.IsNullOrEmpty(fileName) == false, "Coverage file name not found in trx file: {0}",
trxFilePath);
return Path.Combine(resultsDirectory, deploymentDir, "In", fileName);
}
}
}
}
32 changes: 0 additions & 32 deletions test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,37 +283,5 @@ private void AssertSourceFileName(XmlNode module)

Assert.IsTrue(found);
}

private static string GetCoverageFileNameFromTrx(string trxFilePath, string resultsDirectory)
{
Assert.IsTrue(File.Exists(trxFilePath), "Trx file not found: {0}", trxFilePath);
XmlDocument doc = new XmlDocument();
using (var trxStream = new FileStream(trxFilePath, FileMode.Open, FileAccess.Read))
{
doc.Load(trxStream);
var deploymentElements = doc.GetElementsByTagName("Deployment");
Assert.IsTrue(deploymentElements.Count == 1,
"None or more than one Deployment tags found in trx file:{0}", trxFilePath);
var deploymentDir = deploymentElements[0].Attributes.GetNamedItem("runDeploymentRoot")?.Value;
Assert.IsTrue(string.IsNullOrEmpty(deploymentDir) == false,
"runDeploymentRoot attribute not found in trx file:{0}", trxFilePath);
var collectors = doc.GetElementsByTagName("Collector");

string fileName = string.Empty;
for (int i = 0; i < collectors.Count; i++)
{
if (string.Equals(collectors[i].Attributes.GetNamedItem("collectorDisplayName").Value,
"Code Coverage", StringComparison.OrdinalIgnoreCase))
{
fileName = collectors[i].FirstChild?.FirstChild?.FirstChild?.Attributes.GetNamedItem("href")
?.Value;
}
}

Assert.IsTrue(string.IsNullOrEmpty(fileName) == false, "Coverage file name not found in trx file: {0}",
trxFilePath);
return Path.Combine(resultsDirectory, deploymentDir, "In", fileName);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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.IO.Compression;
using System.Linq;

using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class TestPlatformNugetPackageTests : CodeCoverageAcceptanceTestBase
{
private static string nugetPackageFolder;
private string resultsDirectory;

[ClassInitialize]
public static void ClassInit(TestContext testContext)
{
var packageLocation = Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, "artifacts", IntegrationTestEnvironment.BuildConfiguration, "packages");
var nugetPackage = Directory.EnumerateFiles(packageLocation, "Microsoft.TestPlatform.*.nupkg").OrderBy(a => a).FirstOrDefault();
nugetPackageFolder = Path.Combine(packageLocation, Path.GetFileNameWithoutExtension(nugetPackage));
ZipFile.ExtractToDirectory(nugetPackage, nugetPackageFolder);

Directory.Move(Path.Combine(nugetPackageFolder, "tools", "net451", "Team%20Tools"), Path.Combine(nugetPackageFolder, "tools", "net451", "Team Tools"));
Directory.Move(Path.Combine(nugetPackageFolder, "tools", "net451", "Team Tools", "Dynamic%20Code%20Coverage%20Tools"), Path.Combine(nugetPackageFolder, "tools", "net451", "Team Tools", "Dynamic Code Coverage Tools"));
}

[ClassCleanup]
public static void ClassCleanup()
{
//Directory.Delete(nugetPackageFolder, true);
jakubch1 marked this conversation as resolved.
Show resolved Hide resolved
}

[TestInitialize]
public void SetUp()
{
this.resultsDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
}

[TestCleanup]
public void CleanUp()
{
//Directory.Delete(resultsDirectory, true);
jakubch1 marked this conversation as resolved.
Show resolved Hide resolved
}

[TestMethod]
[NetFullTargetFrameworkDataSource(useCoreRunner: false)]
[NetCoreTargetFrameworkDataSource(useCoreRunner: false)]
public void RunMultipleTestAssembliesWithCodeCoverage(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject.dll", "SimpleTestProject2.dll").Trim('\"');

var arguments = CreateCodeCoverageArguments(runnerInfo, assemblyPaths, out var trxFilePath);
this.InvokeVsTest(arguments);

this.ExitCodeEquals(1); // failing tests

var actualCoverageFile = CodeCoverageTests.GetCoverageFileNameFromTrx(trxFilePath, resultsDirectory);
Console.WriteLine($@"Coverage file: {actualCoverageFile} Results directory: {resultsDirectory} trxfile: {trxFilePath}");
Assert.IsTrue(File.Exists(actualCoverageFile), "Coverage file not found: {0}", actualCoverageFile);

Directory.Delete(this.resultsDirectory, true);
}

public override string GetConsoleRunnerPath()
{
string consoleRunnerPath = string.Empty;

if (this.IsDesktopRunner())
{
consoleRunnerPath = Path.Combine(nugetPackageFolder, "tools", "net451", "Common7", "IDE", "Extensions", "TestPlatform", "vstest.console.exe");
}

Assert.IsTrue(File.Exists(consoleRunnerPath), "GetConsoleRunnerPath: Path not found: {0}", consoleRunnerPath);
return consoleRunnerPath;
}

private string CreateCodeCoverageArguments(
RunnerInfo runnerInfo,
string assemblyPaths,
out string trxFilePath)
{
string diagFileName = Path.Combine(this.resultsDirectory, "diaglog.txt");

var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty,
this.FrameworkArgValue, runnerInfo.InIsolationValue);

arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDirectory}", $" /Diag:{diagFileName}", $" /EnableCodeCoverage");

trxFilePath = Path.Combine(this.resultsDirectory, Guid.NewGuid() + ".trx");
arguments = string.Concat(arguments, " /logger:trx;logfilename=" + trxFilePath);

return arguments;
}
}
}