Skip to content

Commit

Permalink
committing new tests for microsoft#958
Browse files Browse the repository at this point in the history
  • Loading branch information
DineshChirnanchu committed Sep 13, 2019
1 parent e89a48c commit 65418b7
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 31 deletions.
Expand Up @@ -27,6 +27,8 @@ internal class TestPluginDiscoverer
{
private IFileHelper fileHelper;

private static List<string> UnloadableFiles = new List<string>();

/// <summary>
/// Initializes a new instance of the <see cref="TestPluginDiscoverer"/> class.
/// </summary>
Expand Down Expand Up @@ -103,7 +105,7 @@ private void AddKnownExtensions(ref IEnumerable<string> extensionPaths)
// In UWP .Net Native Compilation mode managed dll's are packaged differently, & File.Exists() fails.
// Include these two dll's if so far no adapters(extensions) were found, & let Assembly.Load() fail if they are not present.
extensionPaths = extensionPaths.Concat(new[] { "Microsoft.VisualStudio.TestTools.CppUnitTestFramework.CppUnitTestExtension.dll", "Microsoft.VisualStudio.TestPlatform.Extensions.MSAppContainerAdapter.dll" });
}
}

/// <summary>
/// Gets test extension information from the given colletion of files.
Expand Down Expand Up @@ -132,6 +134,10 @@ private void AddKnownExtensions(ref IEnumerable<string> extensionPaths)
// Scan each of the files for data extensions.
foreach (var file in files)
{
if(UnloadableFiles.Contains(file))
{
continue;
}
try
{
Assembly assembly = null;
Expand All @@ -142,17 +148,16 @@ private void AddKnownExtensions(ref IEnumerable<string> extensionPaths)
this.GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(assembly, pluginInfos);
}
}
catch (FileLoadException e)
{
EqtTrace.Warning("TestPluginDiscoverer: Failed to load extensions from file '{0}'. Skipping test extension scan for this file. Error: {1}", file, e);
string entensionTypeInfo = TestPlatformConstants.entensionTypeInfo.Where(x => x.Equals(pluginInfos.GetType().GetGenericArguments()[1].GetTypeInfo().Name)).Select(x=>x).FirstOrDefault().ToString();
string fileLoadErrorMessage = string.Format(CultureInfo.CurrentUICulture, CommonResources.FailedToLoadAdapaterFile, entensionTypeInfo, file);
TestSessionMessageLogger.Instance.SendMessage(TestMessageLevel.Warning, fileLoadErrorMessage);
}
catch (Exception e)
{
EqtTrace.Warning("TestPluginDiscoverer: Failed to load extensions from file '{0}'. Skipping test extension scan for this file. Error: {1}", file, e);
continue;

if (e is FileLoadException)
{
string fileLoadErrorMessage = string.Format(CultureInfo.CurrentUICulture, CommonResources.FailedToLoadAdapaterFile, file);
TestSessionMessageLogger.Instance.SendMessage(TestMessageLevel.Warning, fileLoadErrorMessage);
UnloadableFiles.Add(file);
}
}
}
}
Expand All @@ -172,8 +177,8 @@ private void AddKnownExtensions(ref IEnumerable<string> extensionPaths)
{
Debug.Assert(assembly != null, "null assembly");
Debug.Assert(pluginInfos != null, "null pluginInfos");

Type[] types;

try
{
types = assembly.GetTypes();
Expand All @@ -189,7 +194,6 @@ private void AddKnownExtensions(ref IEnumerable<string> extensionPaths)
EqtTrace.Warning("LoaderExceptions: {0}", ex);
}
}

return;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.Common/Resources/Resources.resx
Expand Up @@ -154,7 +154,7 @@
<value>Failed to find the list of installed unit test extensions. Reason: {0}</value>
</data>
<data name="FailedToLoadAdapaterFile" xml:space="preserve">
<value>The extension of type '{0}' is failed to load extensions from file '{1}'.</value>
<value>Failed to load extensions from file '{0}'. Please use /diag for more information.</value>
</data>
<data name="FastFilterException" xml:space="preserve">
<value>An error occured while creating Fast filter.</value>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -147,7 +147,7 @@
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -270,7 +270,7 @@
<note />
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>The extension of type '{0}' is failed to load extensions from file '{1}'.</source>
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
<note></note>
</trans-unit>
Expand Down
Expand Up @@ -10,10 +10,12 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Discovery
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -29,12 +31,14 @@ public class DiscoveryManagerTests
private DiscoveryManager discoveryManager;
private Mock<IRequestData> mockRequestData;
private Mock<IMetricsCollection> mockMetricsCollection;
private TestSessionMessageLogger sessionLogger;

[TestInitialize]
public void TestInit()
{
this.mockRequestData = new Mock<IRequestData>();
this.mockMetricsCollection = new Mock<IMetricsCollection>();
this.sessionLogger = TestSessionMessageLogger.Instance;
this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object);
this.discoveryManager = new DiscoveryManager(this.mockRequestData.Object);
}
Expand Down Expand Up @@ -148,7 +152,7 @@ public void DiscoverTestsShouldDiscoverTestsInTheSpecifiedSource()
var mockLogger = new Mock<ITestDiscoveryEventsHandler2>();

this.discoveryManager.DiscoverTests(criteria, mockLogger.Object);

// Assert that the tests are passed on via the handletestruncomplete event.
mockLogger.Verify(l => l.HandleDiscoveryComplete(It.IsAny<DiscoveryCompleteEventArgs>(), It.IsAny<IEnumerable<TestCase>>()), Times.Once);
}
Expand Down Expand Up @@ -222,6 +226,25 @@ public void DiscoverTestsShouldCollectMetrics()
mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.TotalTestsDiscovered, It.IsAny<object>()), Times.Once);
}

[TestMethod]
public void DiscoveryInitializeShouldVerifyWarningMessageIfAdapterFailedToLoad()
{
var assemblyLocation = typeof(DiscoveryManagerTests).GetTypeInfo().Assembly.Location;
var mockLogger = new Mock<ITestDiscoveryEventsHandler2>();
TestPluginCacheTests.SetupMockExtensions(
new string[] { assemblyLocation },
() => { });

//Act
this.discoveryManager.Initialize(new List<string> { assemblyLocation }, mockLogger.Object);

//when handler instance returns warning
sessionLogger.SendMessage(TestMessageLevel.Warning, "verify that it is downgraded to warning");

// Verify.
mockLogger.Verify(rd => rd.HandleLogMessage(TestMessageLevel.Warning, "verify that it is downgraded to warning"), Times.Once);
}

#endregion
}
}
Expand Up @@ -11,6 +11,7 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Execution
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.Common.SettingsProvider;
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution;
Expand All @@ -33,16 +34,18 @@ public class ExecutionManagerTests
private ExecutionManager executionManager;
private TestExecutionContext testExecutionContext;
private Mock<IRequestData> mockRequestData;
private TestSessionMessageLogger sessionLogger;

[TestInitialize]
public void TestInit()
{
this.mockRequestData = new Mock<IRequestData>();
this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(new NoOpMetricsCollection());
this.sessionLogger = TestSessionMessageLogger.Instance;
this.executionManager = new ExecutionManager(new RequestData
{
MetricsCollection = new NoOpMetricsCollection()
});
{
MetricsCollection = new NoOpMetricsCollection()
});

TestPluginCache.Instance = null;

Expand Down Expand Up @@ -210,5 +213,48 @@ public void StartTestRunShouldAbortTheRunIfAnyExceptionComesForTheProvidedSource
mockTestRunEventsHandler.Verify(treh => treh.HandleTestRunComplete(It.IsAny<TestRunCompleteEventArgs>(), null, null, null), Times.Once);
mockTestRunEventsHandler.Verify(treh => treh.HandleLogMessage(TestMessageLevel.Error, It.IsAny<string>()), Times.Once);
}

[TestMethod]
public void InitializeShouldVerifyWarningMessageIfAdapterFailedToLoad()
{
var assemblyLocation = typeof(ExecutionManagerTests).GetTypeInfo().Assembly.Location;
var mockLogger = new Mock<ITestMessageEventHandler>();
TestPluginCacheTests.SetupMockExtensions(
new string[] { assemblyLocation },
() => { });

//Act
this.executionManager.Initialize(new List<string> { assemblyLocation }, mockLogger.Object);

//when handler instance returns warning
sessionLogger.SendMessage(TestMessageLevel.Warning, "verify that it is downgraded to warning");

// Verify.
mockLogger.Verify(rd => rd.HandleLogMessage(TestMessageLevel.Warning, "verify that it is downgraded to warning"), Times.Once);
}

[TestMethod]
public void InitializeShouldVerifyThatItIsNotNullIfAdapterFailedToLoad()
{
var mockLogger = new Mock<ITestMessageEventHandler>();

//when handler instance is not null
sessionLogger.SendMessage(TestMessageLevel.Informational, "verify that it is not null");

// Verify.
mockLogger.Verify(rd => rd.HandleLogMessage(TestMessageLevel.Informational, "verify that it is not null"), Times.Never);
}

[TestMethod]
public void InitializeShouldVerifyThatItIsNullIfAdapterFailedToLoad()
{
var mockLogger = new Mock<ITestMessageEventHandler>();

//when handler instance is null
sessionLogger.SendMessage(It.IsAny<TestMessageLevel>(), "verify null");

// Verify.
mockLogger.Verify(rd => rd.HandleLogMessage(It.IsAny<TestMessageLevel>(), "verify null"), Times.Never);
}
}
}

0 comments on commit 65418b7

Please sign in to comment.