Skip to content

Commit

Permalink
Modified the integration tests to use temp folder (#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
Haplois committed Feb 15, 2021
1 parent 6b625d4 commit d788ad8
Show file tree
Hide file tree
Showing 29 changed files with 373 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace Microsoft.TestPlatform.AcceptanceTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

using Microsoft.TestPlatform.TestUtilities;

public class AcceptanceTestBase : IntegrationTestBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void RunTestExecutionWithDisableAppDomain(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var testResults = GetResultsDirectory();
var testAppDomainDetailFileName = Path.Combine(Path.GetTempPath(), "appdomain_test.txt");
var dataCollectorAppDomainDetailFileName = Path.Combine(Path.GetTempPath(), "appdomain_datacollector.txt");

Expand All @@ -36,13 +37,15 @@ public void RunTestExecutionWithDisableAppDomain(RunnerInfo runnerInfo)
this.GetTestAdapterPath(),
runsettingsFilePath,
this.FrameworkArgValue,
runnerInfo.InIsolationValue);
runnerInfo.InIsolationValue,
testResults);

this.InvokeVsTest(arguments);

Assert.IsTrue(IsFilesContentEqual(testAppDomainDetailFileName, dataCollectorAppDomainDetailFileName), "Different AppDomains, test: {0} datacollector: {1}", File.ReadAllText(testAppDomainDetailFileName), File.ReadAllText(dataCollectorAppDomainDetailFileName));
this.ValidateSummaryStatus(1, 1, 1);
File.Delete(runsettingsFilePath);
TryRemoveDirectory(testResults);
}

private static bool IsFilesContentEqual(string filePath1, string filePath2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void PassingInvalidArgumentsToVsTestConsoleShouldNotPrintHelpMessage(Runn
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var arguments = PrepareArguments(this.GetSampleTestAssembly(), this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue);
var testResults = GetResultsDirectory();
var arguments = PrepareArguments(this.GetSampleTestAssembly(), this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, resultsDirectory: testResults);
arguments = string.Concat(arguments, " /badArgument");

this.InvokeVsTest(arguments);
Expand All @@ -56,6 +57,8 @@ public void PassingInvalidArgumentsToVsTestConsoleShouldNotPrintHelpMessage(Runn

//Check for message which guides using help option
this.StdErrorContains("Please use the /help option to check the list of valid arguments");

TryRemoveDirectory(testResults);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.TestPlatform.AcceptanceTests
{
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -24,18 +25,15 @@ public class BlameDataCollectorTests : AcceptanceTestBase

public BlameDataCollectorTests()
{
this.resultsDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
this.resultsDir = GetResultsDirectory();
}

[TestCleanup]
public void Cleanup()
{
Environment.SetEnvironmentVariable("PROCDUMP_PATH", null);

if (Directory.Exists(this.resultsDir))
{
Directory.Delete(this.resultsDir, true);
}
TryRemoveDirectory(resultsDir);
}

[TestMethod]
Expand Down Expand Up @@ -64,7 +62,7 @@ public void BlameDataCollectorShouldOutputDumpFile(RunnerInfo runnerInfo)
{
Environment.SetEnvironmentVariable("PROCDUMP_PATH", Path.Combine(this.testEnvironment.PackageDirectory, @"procdump\0.0.1\bin"));

AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject3.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, string.Empty, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, $" /Blame:CollectDump");
Expand All @@ -91,7 +89,7 @@ public void BlameDataCollectorShouldNotOutputDumpFileWhenNoCrashOccurs(RunnerInf
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDir}");
arguments = string.Concat(arguments, " /testcasefilter:PassingTest");
this.InvokeVsTest(arguments);

Assert.IsFalse(this.StdOut.Contains(".dmp"), "it should not collect a dump, because nothing crashed");
}

Expand Down Expand Up @@ -245,8 +243,8 @@ private void ValidateDump(int expectedDumpCount = 1)

if (dumps.Count < expectedDumpCount)
{
throw new AssertFailedException($"Expected at least {expectedDumpCount} dump file in Attachments, but there were {dumps.Count}."
+ Environment.NewLine
throw new AssertFailedException($"Expected at least {expectedDumpCount} dump file in Attachments, but there were {dumps.Count}."
+ Environment.NewLine
+ string.Join(Environment.NewLine, dumps));
}

Expand Down
9 changes: 4 additions & 5 deletions test/Microsoft.TestPlatform.AcceptanceTests/CUITTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ private void CUITRunAll(string runnerFramework)
}

var assemblyAbsolutePath = testEnvironment.GetTestAsset("CUITTestProject.dll", "net451");
var arguments = PrepareArguments(
assemblyAbsolutePath,
string.Empty,
string.Empty,
this.FrameworkArgValue);
var resultsDirectory = GetResultsDirectory();
var arguments = PrepareArguments(assemblyAbsolutePath, string.Empty, string.Empty, this.FrameworkArgValue, resultsDirectory: resultsDirectory);

this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);

TryRemoveDirectory(resultsDirectory);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CodeCoverageTests : CodeCoverageAcceptanceTestBase

public CodeCoverageTests()
{
this.resultsDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
this.resultsDirectory = GetResultsDirectory();
}

[TestMethod]
Expand Down Expand Up @@ -208,8 +208,8 @@ private void CollectCodeCoverage(RunnerInfo runnerInfo, TestParameters testParam

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}",
this.FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory);
arguments = string.Concat(arguments, $" /Diag:{diagFileName}",
$" /TestAdapterPath:{traceDataCollectorDir}");
arguments = string.Concat(arguments, $" /Platform:{testParameters.TargetPlatform}");

Expand Down
60 changes: 27 additions & 33 deletions test/Microsoft.TestPlatform.AcceptanceTests/DataCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,32 @@ namespace Microsoft.TestPlatform.AcceptanceTests
[TestClass]
public class DataCollectionTests : AcceptanceTestBase
{
private readonly string resultsDir;

public DataCollectionTests()
{
this.resultsDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
}

[TestCleanup]
public void Cleanup()
{
if (Directory.Exists(this.resultsDir))
{
Directory.Delete(this.resultsDir, true);
}
}

[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
public void ExecuteTestsWithDataCollection(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var resultsDir = GetResultsDirectory();
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject2.dll").Trim('\"');
string runSettings = this.GetRunsettingsFilePath();
string diagFileName = Path.Combine(this.resultsDir, "diaglog.txt");
string runSettings = this.GetRunsettingsFilePath(resultsDir);
string diagFileName = Path.Combine(resultsDir, "diaglog.txt");
var extensionsPath = Path.Combine(
this.testEnvironment.TestAssetsPath,
Path.GetFileNameWithoutExtension("OutOfProcDataCollector"),
"bin",
IntegrationTestEnvironment.BuildConfiguration,
this.testEnvironment.RunnerFramework);
var arguments = PrepareArguments(assemblyPaths, null, runSettings, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDir}", $" /Diag:{diagFileName}", $" /TestAdapterPath:{extensionsPath}");
var arguments = PrepareArguments(assemblyPaths, null, runSettings, this.FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: resultsDir);
arguments = string.Concat(arguments, $" /Diag:{diagFileName}", $" /TestAdapterPath:{extensionsPath}");

this.InvokeVsTest(arguments);

this.ValidateSummaryStatus(1, 1, 1);
this.VaildateDataCollectorOutput();
this.VaildateDataCollectorOutput(resultsDir);

TryRemoveDirectory(resultsDir);
}

[TestMethod]
Expand All @@ -64,22 +51,25 @@ public void ExecuteTestsWithDataCollectionUsingCollectArgument(RunnerInfo runner
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var resultsDir = GetResultsDirectory();
var assemblyPaths = this.BuildMultipleAssemblyPath("SimpleTestProject2.dll").Trim('\"');
string diagFileName = Path.Combine(this.resultsDir, "diaglog.txt");
string diagFileName = Path.Combine(resultsDir, "diaglog.txt");
var extensionsPath = Path.Combine(
this.testEnvironment.TestAssetsPath,
Path.GetFileNameWithoutExtension("OutOfProcDataCollector"),
"bin",
IntegrationTestEnvironment.BuildConfiguration,
this.testEnvironment.RunnerFramework);

var arguments = PrepareArguments(assemblyPaths, null, null, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDir}", $" /Diag:{diagFileName}", $" /Collect:SampleDataCollector", $" /TestAdapterPath:{extensionsPath}");
var arguments = PrepareArguments(assemblyPaths, null, null, this.FrameworkArgValue, runnerInfo.InIsolationValue, resultsDir);
arguments = string.Concat(arguments, $" /Diag:{diagFileName}", $" /Collect:SampleDataCollector", $" /TestAdapterPath:{extensionsPath}");

this.InvokeVsTest(arguments);

this.ValidateSummaryStatus(1, 1, 1);
this.VaildateDataCollectorOutput();
this.VaildateDataCollectorOutput(resultsDir);

TryRemoveDirectory(resultsDir);
}

[TestMethod]
Expand All @@ -88,10 +78,13 @@ public void DataCollectorAssemblyLoadingShouldNotThrowErrorForNetCore(RunnerInfo
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var arguments = PrepareArguments(GetAssetFullPath("AppDomainGetAssembliesTestProject.dll", "netcoreapp2.1"), string.Empty, string.Empty, this.FrameworkArgValue);
var resultsDir = GetResultsDirectory();
var arguments = PrepareArguments(GetAssetFullPath("AppDomainGetAssembliesTestProject.dll", "netcoreapp2.1"), string.Empty, string.Empty, this.FrameworkArgValue, resultsDirectory: resultsDir);

this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);

TryRemoveDirectory(resultsDir);
}

[TestMethod]
Expand All @@ -101,10 +94,13 @@ public void DataCollectorAssemblyLoadingShouldNotThrowErrorForFullFramework(Runn
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var arguments = PrepareArguments(GetAssetFullPath("AppDomainGetAssembliesTestProject.dll"), string.Empty, string.Empty, this.FrameworkArgValue);
var resultsDir = GetResultsDirectory();
var arguments = PrepareArguments(GetAssetFullPath("AppDomainGetAssembliesTestProject.dll"), string.Empty, string.Empty, this.FrameworkArgValue, resultsDirectory: resultsDir);

this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 0, 0);

TryRemoveDirectory(resultsDir);
}

private static void CreateDataCollectionRunSettingsFile(string destinationRunsettingsPath, Dictionary<string, string> dataCollectionAttributes)
Expand Down Expand Up @@ -133,7 +129,7 @@ private static void CreateDataCollectionRunSettingsFile(string destinationRunset
}
}

private void VaildateDataCollectorOutput()
private void VaildateDataCollectorOutput(string resultsDir)
{
// Output of datacollection attachment.
this.StdOutputContains("filename.txt");
Expand All @@ -153,7 +149,7 @@ private void VaildateDataCollectorOutput()
var testCaseLevelAttachmentsCount = 0;
var diaglogsFileCount = 0;

var resultFiles = Directory.GetFiles(this.resultsDir, "*.txt", SearchOption.AllDirectories);
var resultFiles = Directory.GetFiles(resultsDir, "*.txt", SearchOption.AllDirectories);

foreach (var file in resultFiles)
{
Expand All @@ -180,11 +176,9 @@ private void VaildateDataCollectorOutput()
Assert.AreEqual(3, diaglogsFileCount);
}

private string GetRunsettingsFilePath()
private string GetRunsettingsFilePath(string resultsDir)
{
var runsettingsPath = Path.Combine(
Path.GetTempPath(),
"test_" + Guid.NewGuid() + ".runsettings");
var runsettingsPath = Path.Combine(resultsDir, "test_" + Guid.NewGuid() + ".runsettings");
var dataCollectionAttributes = new Dictionary<string, string>();

dataCollectionAttributes.Add("friendlyName", "SampleDataCollector");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.TestPlatform.AcceptanceTests
{
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System;

[TestClass]
Expand All @@ -18,14 +19,17 @@ public void RunningTestWithAFailingDebugAssertDoesNotCrashTheHostingProcess(Runn
// is to not crash the process when we are running in debug, and debugger is attached
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var resultsDir = GetResultsDirectory();
var assemblyPath = this.BuildMultipleAssemblyPath("CrashingOnDebugAssertTestProject.dll").Trim('\"');
var arguments = PrepareArguments(assemblyPath, null, null, this.FrameworkArgValue, runnerInfo.InIsolationValue);
var arguments = PrepareArguments(assemblyPath, null, null, this.FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: resultsDir);
this.InvokeVsTest(arguments);

// this will have failed tests when our trace listener works and crash the testhost process when it does not
// because crashing processes is what a failed Debug.Assert does by default, unless you have a debugger attached
this.ValidateSummaryStatus(passedTestsCount: 4, failedTestsCount: 4, 0);
StringAssert.Contains(this.StdOut, "threw exception: Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException:");

TryRemoveDirectory(resultsDir);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Collections.Generic;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -66,15 +67,13 @@ public void CopyAdapterToExtensions()
[TestMethod]
public void VerifyDeprecatedWarningIsThrownWhenAdaptersPickedFromExtensionDirectory()
{
var arguments = PrepareArguments(
this.GetSampleTestAssembly(),
null,
null,
this.FrameworkArgValue);
var resultsDir = GetResultsDirectory();
var arguments = PrepareArguments(this.GetSampleTestAssembly(), null, null, this.FrameworkArgValue, resultsDirectory: resultsDir);

this.InvokeVsTest(arguments);

this.StdOutputContains("Adapter lookup is being changed, please follow");

TryRemoveDirectory(resultsDir);
}

public override string GetConsoleRunnerPath()
Expand Down

0 comments on commit d788ad8

Please sign in to comment.