How to use LoadTests method of Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery.DiscovererEnumerator class

Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery.DiscovererEnumerator.LoadTests

DiscovererEnumeratorTests.cs

Source:DiscovererEnumeratorTests.cs Github

copy

Full Screen

...57 JsonTestDiscoverer.Reset();58 NotImplementedTestDiscoverer.Reset();59 }60 [TestMethod]61 public void LoadTestsShouldReportWarningOnNoDiscoverers()62 {63 TestPluginCacheHelper.SetupMockExtensions(64 new string[] { typeof(TestPluginCache).GetTypeInfo().Assembly.Location },65 () => { });66 var sources = new List<string> { typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location };67 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();68 extensionSourceMap.Add("_none_", sources);69 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, null, this.messageLoggerMock.Object);70 var messageFormat =71 "No test is available in {0}. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.";72 var message = string.Format(messageFormat, string.Join(" ", sources));73 this.messageLoggerMock.Verify(74 l =>75 l.SendMessage(TestMessageLevel.Warning, message), Times.Once);76 }77 [TestMethod]78 public void LoadTestsShouldNotCallIntoDiscoverersIfNoneMatchesSources()79 {80 TestPluginCacheHelper.SetupMockExtensions(81 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },82 () => { });83 var sources = new List<string> { "temp.jpeg" };84 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();85 extensionSourceMap.Add("_none_", sources);86 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, null, this.messageLoggerMock.Object);87 Assert.IsFalse(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);88 Assert.IsFalse(NativeDllTestDiscoverer.IsNativeDiscoverTestCalled);89 }90 [TestMethod]91 public void LoadTestsShouldCallOnlyNativeDiscovererIfNativeAssembliesPassed()92 {93 TestPluginCacheHelper.SetupMockExtensions(94 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },95 () => { });96 this.mockAssemblyProperties.Setup(pe => pe.GetAssemblyType("native.dll")).Returns(AssemblyType.Native);97 var sources = new List<string>98 {99 "native.dll"100 };101 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();102 extensionSourceMap.Add("_none_", sources);103 string testCaseFilter = "TestFilter";104 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, testCaseFilter, this.messageLoggerMock.Object);105 Assert.IsTrue(NativeDllTestDiscoverer.IsNativeDiscoverTestCalled);106 CollectionAssert.AreEqual(sources, NativeDllTestDiscoverer.Sources.ToList());107 Assert.IsFalse(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);108 Assert.IsFalse(JsonTestDiscoverer.IsDiscoverTestCalled);109 }110 [TestMethod]111 public void LoadTestsShouldCallOnlyManagedDiscovererIfManagedAssembliesPassed()112 {113 TestPluginCacheHelper.SetupMockExtensions(114 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },115 () => { });116 this.mockAssemblyProperties.Setup(pe => pe.GetAssemblyType("managed.dll")).Returns(AssemblyType.Managed);117 var sources = new List<string>118 {119 "managed.dll"120 };121 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();122 extensionSourceMap.Add("_none_", sources);123 string testCaseFilter = "TestFilter";124 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, testCaseFilter, this.messageLoggerMock.Object);125 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);126 CollectionAssert.AreEqual(sources, ManagedDllTestDiscoverer.Sources.ToList());127 Assert.IsFalse(NativeDllTestDiscoverer.IsNativeDiscoverTestCalled);128 Assert.IsFalse(JsonTestDiscoverer.IsDiscoverTestCalled);129 }130 [TestMethod]131 public void LoadTestsShouldCallBothNativeAndManagedDiscoverersWithCorrectSources()132 {133 TestPluginCacheHelper.SetupMockExtensions(134 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },135 () => { });136 this.mockAssemblyProperties.Setup(pe => pe.GetAssemblyType("native.dll")).Returns(AssemblyType.Native);137 this.mockAssemblyProperties.Setup(pe => pe.GetAssemblyType("managed.dll")).Returns(AssemblyType.Managed);138 var nativeSources = new List<string>139 {140 "native.dll"141 };142 var managedSources = new List<string>143 {144 "managed.dll"145 };146 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();147 extensionSourceMap.Add("_none_", nativeSources.Concat(managedSources));148 string testCaseFilter = "TestFilter";149 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, testCaseFilter, this.messageLoggerMock.Object);150 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);151 CollectionAssert.AreEqual(managedSources, ManagedDllTestDiscoverer.Sources.ToList());152 Assert.IsTrue(NativeDllTestDiscoverer.IsNativeDiscoverTestCalled);153 CollectionAssert.AreEqual(nativeSources, NativeDllTestDiscoverer.Sources.ToList());154 Assert.IsFalse(JsonTestDiscoverer.IsDiscoverTestCalled);155 }156 [TestMethod]157 public void LoadTestsShouldCallIntoADiscovererThatMatchesTheSources()158 {159 TestPluginCacheHelper.SetupMockExtensions(160 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },161 () => { });162 var sources = new List<string>163 {164 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location,165 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location166 };167 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();168 extensionSourceMap.Add("_none_", sources);169 string testCaseFilter = "TestFilter";170 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, testCaseFilter, this.messageLoggerMock.Object);171 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);172 Assert.IsFalse(JsonTestDiscoverer.IsDiscoverTestCalled);173 // Also validate that the right set of arguments were passed on to the discoverer.174 CollectionAssert.AreEqual(sources, ManagedDllTestDiscoverer.Sources.ToList());175 Assert.AreEqual(this.runSettingsMock.Object, ManagedDllTestDiscoverer.DiscoveryContext.RunSettings);176 Assert.AreEqual(testCaseFilter, (ManagedDllTestDiscoverer.DiscoveryContext as DiscoveryContext).FilterExpressionWrapper.FilterString);177 Assert.AreEqual(this.messageLoggerMock.Object, ManagedDllTestDiscoverer.MessageLogger);178 Assert.IsNotNull(ManagedDllTestDiscoverer.DiscoverySink);179 }180 [TestMethod]181 public void LoadTestsShouldCallIntoMultipleDiscoverersThatMatchesTheSources()182 {183 TestPluginCacheHelper.SetupMockExtensions(184 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },185 () => { });186 var dllsources = new List<string>187 {188 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location,189 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location190 };191 var jsonsources = new List<string>192 {193 "test1.json",194 "test2.json"195 };196 var sources = new List<string>(dllsources);197 sources.AddRange(jsonsources);198 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();199 extensionSourceMap.Add("_none_", sources);200 var runSettings = this.runSettingsMock.Object;201 string testCaseFilter = "TestFilter";202 this.discovererEnumerator.LoadTests(extensionSourceMap, runSettings, testCaseFilter, this.messageLoggerMock.Object);203 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);204 Assert.IsTrue(JsonTestDiscoverer.IsDiscoverTestCalled);205 // Also validate that the right set of arguments were passed on to the discoverer.206 CollectionAssert.AreEqual(dllsources, ManagedDllTestDiscoverer.Sources.ToList());207 Assert.AreEqual(runSettings, ManagedDllTestDiscoverer.DiscoveryContext.RunSettings);208 Assert.AreEqual(testCaseFilter, (ManagedDllTestDiscoverer.DiscoveryContext as DiscoveryContext).FilterExpressionWrapper.FilterString);209 Assert.AreEqual(this.messageLoggerMock.Object, ManagedDllTestDiscoverer.MessageLogger);210 Assert.IsNotNull(ManagedDllTestDiscoverer.DiscoverySink);211 CollectionAssert.AreEqual(jsonsources, JsonTestDiscoverer.Sources.ToList());212 Assert.AreEqual(runSettings, JsonTestDiscoverer.DiscoveryContext.RunSettings);213 Assert.AreEqual(testCaseFilter, (JsonTestDiscoverer.DiscoveryContext as DiscoveryContext).FilterExpressionWrapper.FilterString);214 Assert.AreEqual(this.messageLoggerMock.Object, JsonTestDiscoverer.MessageLogger);215 Assert.IsNotNull(JsonTestDiscoverer.DiscoverySink);216 }217 [TestMethod]218 public void LoadTestsShouldCallIntoOtherDiscoverersWhenCreatingOneFails()219 {220 TestPluginCacheHelper.SetupMockExtensions(221 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },222 () => { });223 var sources = new List<string>224 {225 "test1.csv",226 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location227 };228 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();229 extensionSourceMap.Add("_none_", sources);230 var runSettings = this.runSettingsMock.Object;231 string testCaseFilter = "TestFilter";232 this.discovererEnumerator.LoadTests(extensionSourceMap, runSettings, testCaseFilter, this.messageLoggerMock.Object);233 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);234 Assert.IsFalse(SingletonTestDiscoverer.IsDiscoverTestCalled);235 // Also validate that the right set of arguments were passed on to the discoverer.236 CollectionAssert.AreEqual(new List<string> { sources[1] }, ManagedDllTestDiscoverer.Sources.ToList());237 Assert.AreEqual(runSettings, ManagedDllTestDiscoverer.DiscoveryContext.RunSettings);238 Assert.AreEqual(testCaseFilter, (ManagedDllTestDiscoverer.DiscoveryContext as DiscoveryContext).FilterExpressionWrapper.FilterString);239 Assert.AreEqual(this.messageLoggerMock.Object, ManagedDllTestDiscoverer.MessageLogger);240 Assert.IsNotNull(ManagedDllTestDiscoverer.DiscoverySink);241 }242 [TestMethod]243 public void LoadTestsShouldCallIntoOtherDiscoverersEvenIfDiscoveryInOneFails()244 {245 TestPluginCacheHelper.SetupMockExtensions(246 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },247 () => { });248 var sources = new List<string>249 {250 "test1.cs",251 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location252 };253 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();254 extensionSourceMap.Add("_none_", sources);255 var runSettings = this.runSettingsMock.Object;256 string testCaseFilter = "TestFilter";257 this.discovererEnumerator.LoadTests(extensionSourceMap, runSettings, testCaseFilter, this.messageLoggerMock.Object);258 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);259 Assert.IsTrue(NotImplementedTestDiscoverer.IsDiscoverTestCalled);260 // Also validate that the right set of arguments were passed on to the discoverer.261 CollectionAssert.AreEqual(new List<string> { sources[1] }, ManagedDllTestDiscoverer.Sources.ToList());262 Assert.AreEqual(runSettings, ManagedDllTestDiscoverer.DiscoveryContext.RunSettings);263 Assert.AreEqual(testCaseFilter, (ManagedDllTestDiscoverer.DiscoveryContext as DiscoveryContext).FilterExpressionWrapper.FilterString);264 Assert.AreEqual(this.messageLoggerMock.Object, ManagedDllTestDiscoverer.MessageLogger);265 Assert.IsNotNull(ManagedDllTestDiscoverer.DiscoverySink);266 // Check if we log the failure.267 var message = string.Format(268 CultureInfo.CurrentUICulture,269 "An exception occurred while test discoverer '{0}' was loading tests. Exception: {1}",270 typeof(NotImplementedTestDiscoverer).Name,271 "The method or operation is not implemented.");272 this.messageLoggerMock.Verify(l => l.SendMessage(TestMessageLevel.Error, message), Times.Once);273 }274 [TestMethod]275 public void LoadTestsShouldCollectMetrics()276 {277 var mockMetricsCollector = new Mock<IMetricsCollection>();278 var dict = new Dictionary<string, object>();279 dict.Add("DummyMessage", "DummyValue");280 TestPluginCacheHelper.SetupMockExtensions(281 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },282 () => { });283 var sources = new List<string>284 {285 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location,286 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location287 };288 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();289 extensionSourceMap.Add("_none_", sources);290 mockMetricsCollector.Setup(mc => mc.Metrics).Returns(dict);291 this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollector.Object);292 string testCaseFilter = "TestFilter";293 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, testCaseFilter, this.messageLoggerMock.Object);294 // Verify.295 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.TimeTakenInSecByAllAdapters, It.IsAny<object>()), Times.Once);296 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.NumberOfAdapterUsedToDiscoverTests, It.IsAny<object>()), Times.Once);297 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.NumberOfAdapterDiscoveredDuringDiscovery, It.IsAny<object>()), Times.Once);298 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.TotalTestsByAdapter + ".discoverer://manageddlldiscoverer/", It.IsAny<object>()), Times.Once);299 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.TimeTakenToDiscoverTestsByAnAdapter + ".discoverer://manageddlldiscoverer/", It.IsAny<object>()), Times.Once);300 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.TotalTestsByAdapter + ".discoverer://nativedlldiscoverer/", It.IsAny<object>()), Times.Once);301 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.TimeTakenToDiscoverTestsByAnAdapter + ".discoverer://nativedlldiscoverer/", It.IsAny<object>()), Times.Once);302 mockMetricsCollector.Verify(rd => rd.Add(TelemetryDataConstants.TimeTakenToLoadAdaptersInSec, It.IsAny<object>()), Times.Once);303 }304 [TestMethod]305 public void LoadTestsShouldNotCallIntoDiscoverersWhenCancelled()306 {307 // Setup308 string[] extensions = new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location };309 TestPluginCacheHelper.SetupMockExtensions(extensions, () => { });310 var dllsources = new List<string>311 {312 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location,313 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location314 };315 var jsonsources = new List<string>316 {317 "test1.json",318 "test2.json"319 };320 var sources = new List<string>(dllsources);321 sources.AddRange(jsonsources);322 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>323 {324 { "_none_", sources }325 };326 // Act327 this.cancellationTokenSource.Cancel();328 var runSettings = this.runSettingsMock.Object;329 string testCaseFilter = "TestFilter";330 this.discovererEnumerator.LoadTests(extensionSourceMap, runSettings, testCaseFilter, this.messageLoggerMock.Object);331 // Validate332 Assert.IsFalse(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);333 Assert.IsFalse(JsonTestDiscoverer.IsDiscoverTestCalled);334 this.messageLoggerMock.Verify(logger => logger.SendMessage(TestMessageLevel.Warning, "Discovery of tests cancelled."), Times.Once);335 }336 [TestMethod]337 public void LoadTestsShouldCallIntoTheAdapterWithTheRightTestCaseSink()338 {339 this.InvokeLoadTestWithMockSetup();340 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);341 Assert.AreEqual(2, this.discoveryResultCache.Tests.Count);342 }343 [TestMethod]344 public void LoadTestsShouldNotShowAnyWarningOnTestsDiscovered()345 {346 this.InvokeLoadTestWithMockSetup();347 Assert.AreEqual(2, this.discoveryResultCache.Tests.Count);348 this.messageLoggerMock.Verify(m => m.SendMessage(TestMessageLevel.Warning, It.IsAny<string>()), Times.Never);349 }350 [TestMethod]351 public void LoadTestShouldInstrumentDiscoveryStart()352 {353 this.InvokeLoadTestWithMockSetup();354 this.mockTestPlatformEventSource.Verify(x => x.DiscoveryStart(), Times.Once);355 }356 [TestMethod]357 public void LoadTestShouldInstrumentDiscoveryStop()358 {359 this.InvokeLoadTestWithMockSetup();360 this.mockTestPlatformEventSource.Verify(x => x.DiscoveryStop(It.IsAny<long>()), Times.Once);361 }362 [TestMethod]363 public void LoadTestShouldInstrumentAdapterDiscoveryStart()364 {365 this.InvokeLoadTestWithMockSetup();366 this.mockTestPlatformEventSource.Verify(x => x.AdapterDiscoveryStart(It.IsAny<string>()), Times.AtLeastOnce);367 }368 [TestMethod]369 public void LoadTestShouldInstrumentAdapterDiscoveryStop()370 {371 this.InvokeLoadTestWithMockSetup();372 this.mockTestPlatformEventSource.Verify(x => x.AdapterDiscoveryStop(It.IsAny<long>()), Times.AtLeastOnce);373 }374 [TestMethod]375 public void LoadTestsShouldIterateOverAllExtensionsInTheMapAndDiscoverTests()376 {377 TestPluginCacheHelper.SetupMockExtensions(378 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },379 () => { });380 var dllsources = new List<string>381 {382 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location,383 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location384 };385 var jsonsources = new List<string>386 {387 "test1.json",388 "test2.json"389 };390 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();391 extensionSourceMap.Add(typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location, jsonsources);392 extensionSourceMap.Add("_none_", dllsources);393 var runSettings = this.runSettingsMock.Object;394 string testCaseFilter = "TestFilter";395 this.discovererEnumerator.LoadTests(extensionSourceMap, runSettings, testCaseFilter, this.messageLoggerMock.Object);396 Assert.IsTrue(ManagedDllTestDiscoverer.IsManagedDiscoverTestCalled);397 Assert.IsTrue(JsonTestDiscoverer.IsDiscoverTestCalled);398 // Also validate that the right set of arguments were passed on to the discoverer.399 CollectionAssert.AreEqual(dllsources, ManagedDllTestDiscoverer.Sources.ToList());400 Assert.AreEqual(runSettings, ManagedDllTestDiscoverer.DiscoveryContext.RunSettings);401 Assert.AreEqual(testCaseFilter, (ManagedDllTestDiscoverer.DiscoveryContext as DiscoveryContext).FilterExpressionWrapper.FilterString);402 Assert.AreEqual(this.messageLoggerMock.Object, ManagedDllTestDiscoverer.MessageLogger);403 Assert.IsNotNull(ManagedDllTestDiscoverer.DiscoverySink);404 CollectionAssert.AreEqual(jsonsources, JsonTestDiscoverer.Sources.ToList());405 Assert.AreEqual(runSettings, JsonTestDiscoverer.DiscoveryContext.RunSettings);406 Assert.AreEqual(testCaseFilter, (JsonTestDiscoverer.DiscoveryContext as DiscoveryContext).FilterExpressionWrapper.FilterString);407 Assert.AreEqual(this.messageLoggerMock.Object, JsonTestDiscoverer.MessageLogger);408 Assert.IsNotNull(JsonTestDiscoverer.DiscoverySink);409 }410 [TestMethod]411 public void LoadTestsShouldLogWarningMessageOnNoTestsInAssemblies()412 {413 DiscovererEnumeratorTests.SetupForNoTestsAvailableInGivenAssemblies(out var extensionSourceMap, out var sourcesString);414 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, null, this.messageLoggerMock.Object);415 var expectedMessage =416 $"No test is available in {sourcesString}. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.";417 this.messageLoggerMock.Verify(l => l.SendMessage(TestMessageLevel.Warning, expectedMessage));418 }419 [TestMethod]420 public void LoadTestsShouldLogWarningMessageOnNoTestsInAssembliesWithTestCaseFilter()421 {422 DiscovererEnumeratorTests.SetupForNoTestsAvailableInGivenAssemblies(out var extensionSourceMap, out var sourcesString);423 var testCaseFilter = "Name~TestMethod1";424 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, testCaseFilter, this.messageLoggerMock.Object);425 var expectedMessage =426 $"No test matches the given testcase filter `{testCaseFilter}` in {sourcesString}";427 this.messageLoggerMock.Verify(l => l.SendMessage(TestMessageLevel.Warning, expectedMessage));428 }429 [TestMethod]430 public void LoadTestsShouldShortenTheLongTestCaseFilterWhenNoTestsDiscovered()431 {432 DiscovererEnumeratorTests.SetupForNoTestsAvailableInGivenAssemblies(out var extensionSourceMap, out var sourcesString);433 var veryLengthyTestCaseFilter = "FullyQualifiedName=TestPlatform.CrossPlatEngine" +434 ".UnitTests.Discovery.DiscovererEnumeratorTests." +435 "LoadTestsShouldShortenTheLongTestCaseFilterWhenNoTestsDiscovered" +436 "TestCaseFilterWithVeryLengthTestCaseNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";437 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, veryLengthyTestCaseFilter, this.messageLoggerMock.Object);438 var expectedTestCaseFilter = veryLengthyTestCaseFilter.Substring(0, 256) + "...";439 var expectedMessage =440 $"No test matches the given testcase filter `{expectedTestCaseFilter}` in {sourcesString}";441 this.messageLoggerMock.Verify(l => l.SendMessage(TestMessageLevel.Warning, expectedMessage));442 }443 private static void SetupForNoTestsAvailableInGivenAssemblies(444 out Dictionary<string, IEnumerable<string>> extensionSourceMap,445 out string sourcesString)446 {447 var crossPlatEngineAssemblyLocation = typeof(DiscovererEnumerator).GetTypeInfo().Assembly.Location;448 var objectModelAseeAssemblyLocation = typeof(TestCase).GetTypeInfo().Assembly.Location;449 var sources = new string[] { crossPlatEngineAssemblyLocation, objectModelAseeAssemblyLocation };450 extensionSourceMap = new Dictionary<string, IEnumerable<string>>();451 extensionSourceMap.Add("_none_", sources);452 sourcesString = string.Join(" ", crossPlatEngineAssemblyLocation, objectModelAseeAssemblyLocation);453 }454 private void InvokeLoadTestWithMockSetup()455 {456 TestPluginCacheHelper.SetupMockExtensions(457 new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },458 () => { });459 var sources = new List<string>460 {461 typeof(DiscoveryResultCacheTests).GetTypeInfo().Assembly.Location462 };463 var extensionSourceMap = new Dictionary<string, IEnumerable<string>>();464 extensionSourceMap.Add("_none_", sources);465 this.discovererEnumerator.LoadTests(extensionSourceMap, this.runSettingsMock.Object, null, this.messageLoggerMock.Object);466 }467 #region Implementation468 /// <summary>469 /// Placing this before others so that at runtime this would be the first to be discovered as a discoverer.470 /// </summary>471 [FileExtension(".csv")]472 [DefaultExecutorUri("discoverer://csvdiscoverer")]473 private class SingletonTestDiscoverer : ITestDiscoverer474 {475 private SingletonTestDiscoverer()476 {477 }478 public static bool IsDiscoverTestCalled { get; private set; }479 public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)...

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;10using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;11using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;12using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;13using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;14using System.Reflection;15using System.IO;16{17 {18 static void Main(string[] args)19 {20 var discovererEnumerator = new DiscovererEnumerator();21 var testDiscoverers = discovererEnumerator.LoadTests("C:\\Users\\karan\\Desktop\\TestDiscoverer\\TestDiscoverer\\bin\\Debug\\TestDiscoverer.dll");22 foreach (var testDiscoverer in testDiscoverers)23 {24 Console.WriteLine(testDiscoverer);25 }26 Console.ReadKey();27 }28 }29}

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;9using Microsoft.VisualStudio.TestPlatform.ObjectModel;10using System.Reflection;11{12 {13 static void Main(string[] args)14 {15 var discovererEnumerator = new DiscovererEnumerator();16 var testDiscoverers = discovererEnumerator.GetTestDiscoverers();17 var discoverer = testDiscoverers.First().Value;18 var context = new DiscoveryContext();19 var logger = new ConsoleLogger();20 var discoverySink = new DiscoverySink();21 var settings = new Dictionary<string, object>();22 var discoveryCriteria = new DiscoveryCriteria(new List<string>() { "D:\\test\\1.cs" }, 32, settings);23 var testCases = discoverer.LoadTests(discoveryCriteria, context, logger);24 var testCases1 = testCases.ToList();25 Console.WriteLine(testCases1.Count);26 Console.Read();27 }28 }29}

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;9{10 {11 static void Main(string[] args)12 {13 DiscovererEnumerator discovererEnumerator = new DiscovererEnumerator();14 List<LazyExtension<ITestDiscoverer, ITestDiscovererCapabilities>> testDiscoverers = discovererEnumerator.LoadTests(new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe" }, new List<string>() { "C:\\Program Files (x86)\\Microsoft Visual Studio\\

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;10using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;11{12 {13 static void Main(string[] args)14 {15 var discovererEnumerator = new DiscovererEnumerator();16 var discoverers = discovererEnumerator.GetDiscoverers();17 var discoverer = discoverers.First();18 var path = "C:\\Users\\xxx\\Desktop\\test\\";19 var source = "C:\\Users\\xxx\\Desktop\\test\\test.dll";20 var runSettings = @"<RunSettings><RunConfiguration><TargetFrameworkVersion>.NETFramework,Version=v4.6.1</TargetFrameworkVersion></RunConfiguration></RunSettings>";21 var discoveryCriteria = new DiscoveryCriteria(new List<string> { source }, runSettings, path);22 var logger = new ConsoleLogger();23 var discoveryEvents = new DiscoveryEvents();24 discovererEnumerator.LoadTests(discoverer, discoveryCriteria, logger, discoveryEvents);25 Console.ReadLine();26 }27 }28 {29 public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)30 {31 Console.WriteLine("HandleDiscoveredTests");32 }33 public void HandleDiscoveryComplete(long totalTests, IEnumerable<TestCase> lastChunk)34 {35 Console.WriteLine("HandleDiscoveryComplete");36 }37 public void HandleLogMessage(TestMessageLevel level, string message)38 {39 Console.WriteLine("HandleLogMessage: " + message);40 }41 public void HandleRawMessage(string rawMessage)42 {43 Console.WriteLine("HandleRawMessage");44 }45 }46 {47 public void SendMessage(TestMessageLevel testMessageLevel, string message)48 {49 Console.WriteLine("SendMessage: " + message);50 }51 }52}

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Diagnostics;3using System.IO;4using System.Reflection;5using System.Linq;6using System.Collections.Generic;7using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;8using Microsoft.VisualStudio.TestPlatform.ObjectModel;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;10using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;11using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;12using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;13using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;14using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;15using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine;16using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution;17using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Adapter;18using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager;19using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel;20using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Resources;21using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;22using Microsoft.VisualStudio.TestPlatform.Common;23using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;24using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;25using Microsoft.VisualStudio.TestPlatform.Common.Logging;26using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.EventHandlers;27using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.EventHandlers.Payloads;28using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.Events;29using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.Helpers;30using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.Writers;31using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.Writers.Interfaces;32using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.Writers.TelemetryDataModel;33using Microsoft.VisualStudio.TestPlatform.Common.Utilities;34using Microsoft.VisualStudio.TestPlatform.Common.Utilities.Interfaces;35using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;36using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;37using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Interfaces;38using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Plugins;39using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Plugins.Resources;40using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Plugins.Resources.Messages;41using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities.Interfaces;42using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities.Resources;43using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities.Resources.Messages;44using Microsoft.VisualStudio.TestPlatform.Common.Logging.Interfaces;45using Microsoft.VisualStudio.TestPlatform.Common.Logging.Resources;46using Microsoft.VisualStudio.TestPlatform.Common.Logging.Resources.Messages;47using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.Resources;48using Microsoft.VisualStudio.TestPlatform.Common.Telemetry.Resources.Messages;49using Microsoft.VisualStudio.TestPlatform.Common.Utilities.Resources;50using Microsoft.VisualStudio.TestPlatform.Common.Utilities.Resources.Messages;

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;10using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;11using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;12using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;13using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;14using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;15using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;16using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine;17using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;18using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution;19using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers;20using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources;21using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestRunEventsHandlers;22using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Utilities;23using Microsoft.VisualStudio.TestPlatform.Common;24using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;25using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;26using Microsoft.VisualStudio.TestPlatform.Common.Logging;27using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;28using Microsoft.VisualStudio.TestPlatform.Common.Utilities;29using Microsoft.VisualStudio.TestPlatform.Common.Utilities.Interfaces;30using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;31using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection;32using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;33using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;34using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;35using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Adapter;36using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Adapter.Interfaces;37using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.Base;38using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting;39using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces;40using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources;41using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.RunSettingsProvider;42using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TesthostProviders;43using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Utilities.Interfaces;44using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;45using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;46using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;7using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;8using Microsoft.VisualStudio.TestPlatform.ObjectModel;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;10{11 {12 static void Main(string[] args)13 {14 var discoverer = new DiscovererEnumerator();15 var discoveryContext = new DiscoveryContext();16 var logger = new MockLogger();17 var discoverySink = new MockDiscoverySink();18 var settings = new Dictionary<string, object>();19 var discoveryCriteria = new DiscoveryCriteria(new List<string>() { "C:\\Users\\test\\Desktop\\test\\test1\\test1\\bin\\Debug\\test1.dll" }, 5, string.Empty, settings);20 discoverer.LoadTests(discoveryCriteria, discoveryContext, logger, discoverySink);21 Console.WriteLine("Hello World!");22 }23 }24 {25 public void SendTestCase(TestCase discoveredTest)26 {27 throw new NotImplementedException();28 }29 }30 {31 public void SendMessage(TestMessageLevel testMessageLevel, string message)32 {33 throw new NotImplementedException();34 }35 }36}

Full Screen

Full Screen

LoadTests

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;10using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;11using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution;12using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;13{14 {15 static void Main(string[] args)16 {17 TestContainer testContainer = new TestContainer(args[0]);18 var testPlatform = TestPlatformFactory.GetTestPlatform();19 var testRunCriteria = new TestRunCriteria(new List<string>() { testContainer.Source }, 1, false, null, null, null, null, null, null, null);20 var testDiscoveryRequest = testPlatform.CreateDiscoveryRequest(testRunCriteria, new TestPlatformOptions(), new TestLogger());21 var discovererEnumerator = new DiscovererEnumerator();22 var tests = discovererEnumerator.LoadTests(testContainer, testDiscoveryRequest);23 testRunCriteria = new TestRunCriteria(tests, 1, false, null, null, null, null, null, null, null);24 var testExecutionRequest = testPlatform.CreateTestRunRequest(testRunCriteria, new TestPlatformOptions(), new TestLogger());25 var executionManager = new ExecutionManager();26 executionManager.RunTests(tests, testExecutionRequest);27 Console.ReadKey();28 }29 }30}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful