Skip to content

Commit

Permalink
Added an option to deploy all files in the test source location (#391)
Browse files Browse the repository at this point in the history
* Added an option to deploy the test source dependencies and satellite dlls by default. This option will be on by default.

It can turned off in which case deployment would just deploy the test source location and skip the test results folder if the test results folder is within it.

Added UTs and E2E tests for the change

* Removed couple of redundant tests

* Minor review comment updated.

* Removed and unused file
  • Loading branch information
cltshivash authored and mayankbansal018 committed Oct 31, 2018
1 parent 2be8110 commit e0fb2a8
Show file tree
Hide file tree
Showing 21 changed files with 524 additions and 185 deletions.
27 changes: 27 additions & 0 deletions TestFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataSourceTestProject", "te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DoNotParallelizeTestProject", "test\E2ETests\TestAssets\DoNotParallelizeTestProject\DoNotParallelizeTestProject.csproj", "{8080DE48-CFD9-4F33-908A-8B71108CA223}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeploymentTestProject", "test\E2ETests\TestAssets\DeploymentTestProject\DeploymentTestProject.csproj", "{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompatTestProject", "test\E2ETests\TestAssets\CompatTestProject\CompatTestProject.csproj", "{2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProjectForAssemblyResolution", "test\ComponentTests\TestAssets\TestProjectForAssemblyResolution\TestProjectForAssemblyResolution.csproj", "{0B057B99-DCDD-417A-BC19-3E63DDD86F24}"
Expand Down Expand Up @@ -965,6 +967,30 @@ Global
{8080DE48-CFD9-4F33-908A-8B71108CA223}.Release|x64.Build.0 = Release|Any CPU
{8080DE48-CFD9-4F33-908A-8B71108CA223}.Release|x86.ActiveCfg = Release|Any CPU
{8080DE48-CFD9-4F33-908A-8B71108CA223}.Release|x86.Build.0 = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|Any CPU.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|ARM.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|ARM.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|x64.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|x64.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|x86.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Code Analysis Debug|x86.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|ARM.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|ARM.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|x64.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|x64.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|x86.ActiveCfg = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Debug|x86.Build.0 = Debug|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|Any CPU.Build.0 = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|ARM.ActiveCfg = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|ARM.Build.0 = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|x64.ActiveCfg = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|x64.Build.0 = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|x86.ActiveCfg = Release|Any CPU
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6}.Release|x86.Build.0 = Release|Any CPU
{2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16}.Code Analysis Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16}.Code Analysis Debug|Any CPU.Build.0 = Debug|Any CPU
{2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16}.Code Analysis Debug|ARM.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1069,6 +1095,7 @@ Global
{CD0CA7CD-CED3-45FF-9F36-B1C8DF7A9220} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{5A4967CD-B527-4D43-81C2-4CA90EE10222} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{8080DE48-CFD9-4F33-908A-8B71108CA223} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{0B057B99-DCDD-417A-BC19-3E63DDD86F24} = {1899187D-8B9C-40C2-9F04-9E9A76C9A919}
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="Deployment\TestRunDirectories.cs" />
<Compile Include="Extensions\ExceptionExtensions.cs" />
<Compile Include="Friends.cs" />
<Compile Include="Services\MSTestAdapterSettings.cs" />
<Compile Include="Utilities\AppDomainWrapper.cs" />
<Compile Include="Utilities\IAppDomain.cs" />
<Compile Include="Utilities\SequentialIntPermutation.cs" />
Expand All @@ -77,7 +78,7 @@
<Compile Include="Services\DesktopReflectionOperations.cs" />
<Compile Include="Services\DesktopThreadOperations.cs" />
<Compile Include="Services\DesktopFileOperations.cs" />
<Compile Include="Services\DesktopSettingsProvider.cs" />
<Compile Include="Services\MSTestSettingsProvider.cs" />
<Compile Include="Services\DesktopTestDataSource.cs" />
<Compile Include="Services\DesktopTestDeployment.cs" />
<Compile Include="Services\DesktopTestSource.cs" />
Expand All @@ -93,6 +94,7 @@
<Compile Include="Utilities\IAssemblyUtility.cs" />
<Compile Include="Utilities\RandomIntPermutation.cs" />
<Compile Include="Utilities\ReflectionUtility.cs" />
<Compile Include="Utilities\Validate.cs" />
<Compile Include="Utilities\VSInstallationUtilities.cs" />
<Compile Include="Utilities\XmlUtilities.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ public bool Deploy(IEnumerable<TestCase> tests, IRunContext runContext, IFramewo
return false;
}

var isDeploymentDone = false;

using (new SuspendCodeCoverage())
{
// Group the tests by source
Expand All @@ -153,7 +151,7 @@ group test by test.Source into testGroup
foreach (var group in testsBySource)
{
// do the deployment
isDeploymentDone = this.deploymentUtility.Deploy(@group.Tests, @group.Source, runContext, frameworkHandle, ref runDirectories) || isDeploymentDone;
this.deploymentUtility.Deploy(@group.Tests, @group.Source, runContext, frameworkHandle, RunDirectories);
}

// Update the runDirectories
Expand Down
Original file line number Diff line number Diff line change
@@ -1,81 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// 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.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;

using ISettingsProvider = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ISettingsProvider;

#pragma warning disable SA1649 // File name must match first type name

/// <summary>
/// Class to read settings from the runsettings xml for the desktop.
/// </summary>
public class MSTestSettingsProvider : ISettingsProvider
#pragma warning restore SA1649 // File name must match first type name
{
/// <summary>
/// Member variable for Adapter settings
/// </summary>
private static MSTestAdapterSettings settings;

/// <summary>
/// Gets settings provided to the adapter.
/// </summary>
public static MSTestAdapterSettings Settings
{
get
{
if (settings == null)
{
settings = new MSTestAdapterSettings();
}

return settings;
}
}

/// <summary>
/// Load the settings from the reader.
/// </summary>
/// <param name="reader">Reader to load the settings from.</param>
public void Load(XmlReader reader)
{
ValidateArg.NotNull<XmlReader>(reader, "reader");

settings = MSTestAdapterSettings.ToSettings(reader);
}

public IDictionary<string, object> GetProperties(string source)
{
return TestDeployment.GetDeploymentInformation(source);
}

/// <summary>
/// Reset the settings to its default.
/// Used for testing purposes.
/// </summary>
internal static void Reset()
{
settings = null;
}
}

/// <summary>
/// Adapter Settings for the run
/// </summary>
#pragma warning disable SA1402
public class MSTestAdapterSettings
#pragma warning restore SA1402
{
/// <summary>
/// Initializes a new instance of the <see cref="MSTestAdapterSettings"/> class.
Expand All @@ -84,6 +20,7 @@ public MSTestAdapterSettings()
{
this.DeleteDeploymentDirectoryAfterTestRunIsComplete = true;
this.DeploymentEnabled = true;
this.DeployTestSourceDependencies = true;
this.SearchDirectories = new List<RecursiveDirectoryPath>();
}

Expand All @@ -97,6 +34,11 @@ public MSTestAdapterSettings()
/// </summary>
public bool DeleteDeploymentDirectoryAfterTestRunIsComplete { get; private set; }

/// <summary>
/// Gets a value indicating whether the test source references are to deployed
/// </summary>
public bool DeployTestSourceDependencies { get; private set; }

/// <summary>
/// Gets list of paths recursive or non recursive paths.
/// </summary>
Expand All @@ -107,7 +49,6 @@ public MSTestAdapterSettings()
/// </summary>
/// <param name="reader">Reader to load the settings from.</param>
/// <returns>An instance of the <see cref="MSTestAdapterSettings"/> class</returns>
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Reviewed. Suppression is OK here.")]
public static MSTestAdapterSettings ToSettings(XmlReader reader)
{
ValidateArg.NotNull<XmlReader>(reader, "reader");
Expand All @@ -116,6 +57,7 @@ public static MSTestAdapterSettings ToSettings(XmlReader reader)
//
// <MSTestV2>
// <DeploymentEnabled>true</DeploymentEnabled>
// <DeployTestSourceDependencies>true</DeployTestSourceDependencies>
// <DeleteDeploymentDirectoryAfterTestRunIsComplete>true</DeleteDeploymentDirectoryAfterTestRunIsComplete>
// <AssemblyResolution>
// <Directory path= "% HOMEDRIVE %\direvtory "includeSubDirectories = "true" />
Expand Down Expand Up @@ -151,6 +93,16 @@ public static MSTestAdapterSettings ToSettings(XmlReader reader)
break;
}

case "DEPLOYTESTSOURCEDEPENDENCIES":
{
if (bool.TryParse(reader.ReadInnerXml(), out result))
{
settings.DeployTestSourceDependencies = result;
}

break;
}

case "DELETEDEPLOYMENTDIRECTORYAFTERTESTRUNISCOMPLETE":
{
if (bool.TryParse(reader.ReadInnerXml(), out result))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
using System.Collections.Generic;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

using ISettingsProvider = Interface.ISettingsProvider;

/// <summary>
/// Class to read settings from the runsettings xml for the desktop.
/// </summary>
public class MSTestSettingsProvider : ISettingsProvider
{
/// <summary>
/// Member variable for Adapter settings
/// </summary>
private static MSTestAdapterSettings settings;

/// <summary>
/// Gets settings provided to the adapter.
/// </summary>
public static MSTestAdapterSettings Settings
{
get
{
if (settings == null)
{
settings = new MSTestAdapterSettings();
}

return settings;
}
}

/// <summary>
/// Reset the settings to its default.
/// </summary>
public static void Reset()
{
settings = null;
}

/// <summary>
/// Load the settings from the reader.
/// </summary>
/// <param name="reader">Reader to load the settings from.</param>
public void Load(XmlReader reader)
{
ValidateArg.NotNull(reader, "reader");
settings = MSTestAdapterSettings.ToSettings(reader);
}

public IDictionary<string, object> GetProperties(string source)
{
return TestDeployment.GetDeploymentInformation(source);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -91,14 +92,14 @@ internal bool IsValidDeploymentItem(string sourcePath, string relativeOutputDire
return false;
}

if (sourcePath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) != -1 ||
relativeOutputDirectory.IndexOfAny(System.IO.Path.GetInvalidPathChars()) != -1)
if (sourcePath.IndexOfAny(Path.GetInvalidPathChars()) != -1 ||
relativeOutputDirectory.IndexOfAny(Path.GetInvalidPathChars()) != -1)
{
warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentItemContainsInvalidCharacters, sourcePath, relativeOutputDirectory);
return false;
}

if (System.IO.Path.IsPathRooted(relativeOutputDirectory))
if (Path.IsPathRooted(relativeOutputDirectory))
{
warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentItemOutputDirectoryMustBeRelative, relativeOutputDirectory);
return false;
Expand All @@ -123,18 +124,15 @@ internal bool HasDeploymentItems(TestCase testCase)
internal IList<DeploymentItem> GetDeploymentItems(IEnumerable<TestCase> tests)
{
List<DeploymentItem> allDeploymentItems = new List<DeploymentItem>();

foreach (var test in tests)
{
KeyValuePair<string, string>[] items = this.GetDeploymentItems(test);

if (items == null || items.Length == 0)
{
continue;
}

IList<DeploymentItem> deploymentItemsToBeAdded = this.FromKeyValuePairs(items);

foreach (var deploymentItemToBeAdded in deploymentItemsToBeAdded)
{
this.AddDeploymentItem(allDeploymentItems, deploymentItemToBeAdded);
Expand Down
Loading

0 comments on commit e0fb2a8

Please sign in to comment.