How to use TestPlatform method of Microsoft.VisualStudio.TestPlatform.Client.TestPlatform class

Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.Client.TestPlatform.TestPlatform

TestRunner.cs

Source:TestRunner.cs Github

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;2using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;5using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;6using System;7using System.Collections.Generic;8using System.IO;9using System.Linq;10using System.Net.Sockets;11using System.Runtime.Serialization;12using System.Threading;13using System.Threading.Tasks;14namespace MSTestX.Console15{16 public class TestRunner : IDisposable17 {18 private SocketCommunicationManager socket;19 private System.Net.IPEndPoint _endpoint;20 public TestRunner(System.Net.IPEndPoint endpoint = null)21 {22 _endpoint = endpoint;23 }24 public async Task RunTests(string outputFilename, string settingsXml, CancellationToken cancellationToken)25 {26 var loggerEvents = new TestLoggerEventsImpl();27 var logger = new Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.TrxLogger();28 var parameters = new Dictionary<string, string>() { { "TestRunDirectory", "." } };29 if (!string.IsNullOrEmpty(outputFilename))30 parameters.Add("LogFileName", outputFilename);31 logger.Initialize(loggerEvents, parameters);32 try33 {34 await RunTestsInternal(outputFilename, settingsXml, loggerEvents, cancellationToken);35 }36 catch37 {38 if (loggerEvents != null)39 {40 var result = new TestRunCompleteEventArgs(null, false, true, null, null, TimeSpan.Zero); //TRXLogger doesn't use these values anyway41 loggerEvents?.OnTestRunComplete(result);42 }43 throw;44 }45 finally46 {47 socket.StopClient();48 }49 }50 private async Task RunTestsInternal(string outputFilename, string settingsXml, TestLoggerEventsImpl loggerEvents, CancellationToken cancellationToken)51 {52 System.Console.WriteLine("Waiting for connection to test adapter...");53 for (int i = 1; i <= 10; i++)54 {55 socket = new SocketCommunicationManager();56 await socket.SetupClientAsync(_endpoint ?? new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, 38300)).ConfigureAwait(false);57 if (!socket.WaitForServerConnection(10000))58 {59 if (i == 10)60 {61 throw new Exception("No connection to test host could be established. Make sure the app is running in the foreground.");62 }63 else64 {65 System.Console.WriteLine($"Retrying connection.... ({i} of 10)");66 continue;67 }68 }69 break;70 }71 socket.SendMessage(MessageType.SessionConnected); //Start session72 //Perform version handshake73 Message msg = await ReceiveMessageAsync(cancellationToken);74 if (msg?.MessageType == MessageType.VersionCheck)75 {76 var version = JsonDataSerializer.Instance.DeserializePayload<int>(msg);77 var success = version == 1;78 System.Console.WriteLine("Connected to test adapter");79 }80 else81 {82 throw new InvalidOperationException("Handshake failed");83 }84 // Get tests85 socket.SendMessage(MessageType.StartDiscovery,86 new DiscoveryRequestPayload()87 {88 Sources = new string[] { },89 RunSettings = settingsXml ?? @"<?xml version=""1.0"" encoding=""utf-8""?><RunSettings><RunConfiguration /></RunSettings>",90 TestPlatformOptions = null91 });92 int pid = 0;93 while (!cancellationToken.IsCancellationRequested)94 {95 msg = await ReceiveMessageAsync(cancellationToken).ConfigureAwait(false);96 cancellationToken.ThrowIfCancellationRequested();97 if (msg == null)98 {99 continue;100 }101 if (msg.MessageType == MessageType.TestHostLaunched)102 {103 var thl = JsonDataSerializer.Instance.DeserializePayload<TestHostLaunchedPayload>(msg);104 pid = thl.ProcessId;105 System.Console.WriteLine($"Test Host Launched. Process ID '{pid}'");106 }107 else if (msg.MessageType == MessageType.DiscoveryInitialize)108 {109 System.Console.Write("Discovering tests...");110 loggerEvents?.OnDiscoveryStart(new DiscoveryStartEventArgs(new DiscoveryCriteria()));111 }112 else if (msg.MessageType == MessageType.DiscoveryComplete)113 {114 var dcp = JsonDataSerializer.Instance.DeserializePayload<DiscoveryCompletePayload>(msg);115 System.Console.WriteLine($"Discovered {dcp.TotalTests} tests");116 loggerEvents?.OnDiscoveryComplete(new DiscoveryCompleteEventArgs(dcp.TotalTests, false));117 loggerEvents?.OnDiscoveredTests(new DiscoveredTestsEventArgs(dcp.LastDiscoveredTests));118 //Start testrun119 socket.SendMessage(MessageType.TestRunSelectedTestCasesDefaultHost,120 new TestRunRequestPayload() { TestCases = dcp.LastDiscoveredTests.ToList(), RunSettings = settingsXml });121 loggerEvents?.OnTestRunStart(new TestRunStartEventArgs(new TestRunCriteria(dcp.LastDiscoveredTests, 1)));122 }123 else if (msg.MessageType == MessageType.DataCollectionTestStart)124 {125 if (!System.Console.IsOutputRedirected)126 {127 var tcs = JsonDataSerializer.Instance.DeserializePayload<TestCaseStartEventArgs>(msg);128 var testName = tcs.TestCaseName;129 if (string.IsNullOrEmpty(testName))130 testName = tcs.TestElement.DisplayName;131 System.Console.Write($" {testName}");132 }133 }134 else if (msg.MessageType == MessageType.DataCollectionTestEnd)135 {136 //Skip137 }138 else if (msg.MessageType == MessageType.DataCollectionTestEndResult)139 {140 var tr = JsonDataSerializer.Instance.DeserializePayload<Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.TestResultEventArgs>(msg);141 var testName = tr.TestResult.DisplayName;142 if (string.IsNullOrEmpty(testName))143 testName = tr.TestElement.DisplayName;144 var outcome = tr.TestResult.Outcome;145 var parentExecId = tr.TestResult.Properties.Where(t => t.Id == "ParentExecId").Any() ?146 tr.TestResult.GetPropertyValue<Guid>(tr.TestResult.Properties.Where(t => t.Id == "ParentExecId").First(), Guid.Empty) : Guid.Empty;147 if (outcome == Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Failed)148 {149 }150 else if (outcome == Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Skipped)151 {152 System.Console.ForegroundColor = ConsoleColor.Yellow;153 }154 else if (outcome == Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed)155 {156 System.Console.ForegroundColor = ConsoleColor.Green;157 }158 if (!System.Console.IsOutputRedirected)159 {160 System.Console.SetCursorPosition(0, System.Console.CursorTop);161 }162 string testMessage = tr.TestResult?.ErrorMessage;163 if (parentExecId == Guid.Empty || !System.Console.IsOutputRedirected)164 {165 switch(outcome)166 {167 case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed:168 System.Console.ForegroundColor = ConsoleColor.Green;169 System.Console.Write(" √ ");170 break;171 case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Skipped:172 System.Console.ForegroundColor = ConsoleColor.Yellow;173 System.Console.Write(" ! ");174 break;175 case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Failed:176 System.Console.ForegroundColor = ConsoleColor.Red;177 System.Console.Write(" X ");178 break;179 default:180 System.Console.Write(" "); break;181 }182 System.Console.ResetColor();183 System.Console.Write(testName);184 var d = tr.TestResult.Duration;185 if (d.TotalMilliseconds < 1)186 System.Console.WriteLine(" [< 1ms]");187 else if (d.TotalSeconds < 1)188 System.Console.WriteLine($" [{d.Milliseconds}ms]");189 else if (d.TotalMinutes < 1)190 System.Console.WriteLine($" [{d.Seconds}s {d.Milliseconds.ToString("0")}ms]");191 else if (d.TotalHours < 1)192 System.Console.WriteLine($" [{d.Minutes}m {d.Seconds}s {d.Milliseconds.ToString("0")}ms]");193 else if (d.TotalDays < 1)194 System.Console.WriteLine($" [{d.Hours}h {d.Minutes}m {d.Seconds}s {d.Milliseconds.ToString("0")}ms]");195 else196 System.Console.WriteLine($" [{Math.Floor(d.TotalDays)}d {d.Hours}h {d.Minutes}m {d.Seconds}s {d.Milliseconds.ToString("0")}ms]"); // I sure hope your tests won't ever need this line of code197 if (!string.IsNullOrEmpty(testMessage))198 {199 System.Console.ForegroundColor = ConsoleColor.Red;200 System.Console.WriteLine(" Error Message:");201 System.Console.WriteLine(" " + testMessage);202 if (!string.IsNullOrEmpty(tr.TestResult.ErrorStackTrace))203 {204 System.Console.WriteLine(" Stack Trace:");205 System.Console.WriteLine(" " + tr.TestResult.ErrorStackTrace);206 }207 System.Console.ResetColor();208 System.Console.WriteLine();209 // If test failed, also output messages, if any210 if (tr.TestResult.Messages?.Any() == true)211 {212 System.Console.WriteLine(" Standard Output Messages:");213 foreach (var message in tr.TestResult.Messages)214 {215 System.Console.WriteLine(message.Text);216 }217 System.Console.WriteLine();218 }219 } 220 }221 // Make attachment paths absolute222 foreach (var set in tr.TestResult.Attachments)223 {224 for (int i = 0; i < set.Attachments.Count; i++)225 {226 var uri = set.Attachments[i].Uri.OriginalString;227 if (!set.Attachments[i].Uri.IsAbsoluteUri)228 {229 DirectoryInfo d = new DirectoryInfo(".");230 var newPath = Path.Combine(d.FullName, uri);231 newPath = newPath.Replace('/', System.IO.Path.DirectorySeparatorChar);232 set.Attachments[i] = new Microsoft.VisualStudio.TestPlatform.ObjectModel.UriDataAttachment(233 new Uri(newPath, UriKind.Relative), set.Attachments[i].Description);234 }235 }236 }237 loggerEvents?.OnTestResult(new Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestResultEventArgs(tr.TestResult));238 }239 else if (msg.MessageType == MessageType.ExecutionComplete)240 {241 var trc = JsonDataSerializer.Instance.DeserializePayload<TestRunCompletePayload>(msg);242 loggerEvents?.OnTestRunComplete(trc.TestRunCompleteArgs);243 System.Console.WriteLine();244 System.Console.WriteLine("Test Run Complete");245 System.Console.WriteLine($"Total tests: {trc.LastRunTests.TestRunStatistics.ExecutedTests} tests");246 System.Console.ForegroundColor = ConsoleColor.Green;247 System.Console.WriteLine($" Passed : {trc.LastRunTests.TestRunStatistics.Stats[Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed]} ");248 System.Console.ForegroundColor = ConsoleColor.Red;249 System.Console.WriteLine($" Failed : {trc.LastRunTests.TestRunStatistics.Stats[Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Failed]} ");250 System.Console.ForegroundColor = ConsoleColor.Yellow;251 System.Console.WriteLine($" Skipped : {trc.LastRunTests.TestRunStatistics.Stats[Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Skipped]} ");252 System.Console.ResetColor(); 253 System.Console.WriteLine($" Total time: {trc.TestRunCompleteArgs.ElapsedTimeInRunningTests.TotalSeconds} Seconds");254 return; //Test run is complete -> Exit message loop255 }256 else if (msg.MessageType == MessageType.AbortTestRun)257 {258 throw new TaskCanceledException("Test Run Aborted!");259 }260 else if (msg.MessageType == MessageType.CancelTestRun)261 {262 throw new TaskCanceledException("Test Run Cancelled!");263 }264 else if (msg.MessageType == MessageType.TestMessage)265 {266 var tm = JsonDataSerializer.Instance.DeserializePayload<TestMessagePayload>(msg);267 System.Console.WriteLine($"{tm.MessageLevel}: {tm.Message}");268 }269 else if (msg.MessageType == "AttachmentSet")270 {271 var set = JsonDataSerializer.Instance.DeserializePayload<FileAttachmentSet>(msg);272 foreach(var attachment in set.Attachments)273 {274 var path = attachment.Uri.OriginalString;275 try276 {277 var dir = Path.GetDirectoryName(path);278 if (!Directory.Exists(dir))279 Directory.CreateDirectory(dir);280 File.WriteAllBytes(path, attachment.Data);281 }282 catch { }283 }284 }285 else286 {287 System.Console.WriteLine($"Received: {msg.MessageType} -> {msg.Payload}");288 }289 }290 cancellationToken.ThrowIfCancellationRequested();291 }292 private Task<Message> ReceiveMessageAsync(CancellationToken cancellationToken)293 {294 return Task.Run<Message>(() =>295 {296 Message msg = null;297 // Set read timeout to avoid blocking receive raw message298 while (!cancellationToken.IsCancellationRequested)299 {300 try301 {302 msg = socket.ReceiveMessage();303 cancellationToken.ThrowIfCancellationRequested();304 if (msg != null)305 {306 return msg;307 }308 }309 catch (EndOfStreamException endofStreamException)310 {311 throw new Exception("Test run is aborted.", endofStreamException);312 }313 catch (IOException ioException)314 {315 var socketException = ioException.InnerException as SocketException;316 if (socketException != null && socketException.SocketErrorCode == SocketError.TimedOut)317 {318 throw new Exception("Test runner connection timed out", ioException);319 }320 else321 {322 continue;323 }324 }325 catch (System.Exception ex)326 {327 System.Console.WriteLine("Failed to receive message : " + ex.Message);328 continue;329 }330 }331 return msg;332 });333 }334 public void Dispose()335 {336 socket.StopClient();337 }338 private class TestLoggerEventsImpl : TestLoggerEvents339 {340 public void OnTestRunMessage(TestRunMessageEventArgs e) => TestRunMessage?.Invoke(this, e);341 public override event EventHandler<TestRunMessageEventArgs> TestRunMessage;342 public void OnTestRunStart(TestRunStartEventArgs e) => TestRunStart?.Invoke(this, e);343 public override event EventHandler<TestRunStartEventArgs> TestRunStart;344 public void OnTestResult(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestResultEventArgs e) => TestResult?.Invoke(this, e);345 public override event EventHandler<Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestResultEventArgs> TestResult;346 public void OnTestRunComplete(TestRunCompleteEventArgs e) => TestRunComplete?.Invoke(this, e);347 public override event EventHandler<TestRunCompleteEventArgs> TestRunComplete;348 public void OnDiscoveryStart(DiscoveryStartEventArgs e) => DiscoveryStart?.Invoke(this, e);349 public override event EventHandler<DiscoveryStartEventArgs> DiscoveryStart;350 public void OnDiscoveryMessage(TestRunMessageEventArgs e) => DiscoveryMessage?.Invoke(this, e);351 public override event EventHandler<TestRunMessageEventArgs> DiscoveryMessage;352 public void OnDiscoveredTests(DiscoveredTestsEventArgs e) => DiscoveredTests?.Invoke(this, e);353 public override event EventHandler<DiscoveredTestsEventArgs> DiscoveredTests;354 public void OnDiscoveryComplete(DiscoveryCompleteEventArgs e) => DiscoveryComplete?.Invoke(this, e);355 public override event EventHandler<DiscoveryCompleteEventArgs> DiscoveryComplete;356 }357 [DataContract]358 private class FileAttachmentSet359 {...

Full Screen

Full Screen

Common_Friends.cs

Source:Common_Friends.cs Github

copy

Full Screen

1// Copyright (c) Microsoft Corporation. All rights reserved.2// Licensed under the MIT license. See LICENSE file in the project root for full license information.3using System.Runtime.CompilerServices;4#region Product Assemblies5[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CrossPlatEngine, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]6[assembly: InternalsVisibleTo("vstest.console, PublicKey =0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]7[assembly: InternalsVisibleTo("datacollector, PublicKey =0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]8[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CommunicationUtilities, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]9[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Common, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]10[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Client, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]11#endregion12#region Test Assemblies13[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Common.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]14[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CrossPlatEngine.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]15[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]16[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]17[assembly: InternalsVisibleTo("datacollector.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]18[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]19[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CommunicationUtilities.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]20[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Client.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]21[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1364b210712e440efa6b25a553aca2b8c6ae036e4e32a18f62a50b7e6dd7f50fc0453c0e61a70c7c38d4a87c421eebd369be622de316f952c5cfdc171f1654b7bc4bad438ecdf19080be273dda3e6a7e070f2ca68d830202a3515bd6684d4be8d1b9743734e1796da068b4b60f9651c416584e74952baf87422550c81800bab")]22#endregion...

Full Screen

Full Screen

ITranslationLayerRequestSenderAsync.cs

Source:ITranslationLayerRequestSenderAsync.cs Github

copy

Full Screen

1// Copyright (c) Microsoft Corporation. All rights reserved.2// Licensed under the MIT license. See LICENSE file in the project root for full license information.3namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces4{5 using System;6 using System.Collections.Generic;7 using System.Threading.Tasks;8 using Microsoft.VisualStudio.TestPlatform.ObjectModel;9 using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;10 using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;11 /// <summary>12 /// Asynchronous equivalent of <see cref="ITranslationLayerRequestSender"/>.13 /// </summary>14 internal interface ITranslationLayerRequestSenderAsync : IDisposable15 {16 /// <summary>17 /// Asynchronous equivalent of <see cref="ITranslationLayerRequestSender.InitializeCommunication"/>18 /// and <see cref="ITranslationLayerRequestSender.WaitForRequestHandlerConnection(int)"/>.19 /// </summary>20 Task<int> InitializeCommunicationAsync(int clientConnectionTimeout);21 /// <summary>22 /// See <see cref="ITranslationLayerRequestSender.Close"/>23 /// </summary>24 void Close();25 /// <summary>26 /// See <see cref="ITranslationLayerRequestSender.InitializeExtensions"/>27 /// </summary>28 void InitializeExtensions(IEnumerable<string> pathToAdditionalExtensions);29 /// <summary>30 /// Asynchronous equivalent of ITranslationLayerRequestSender.DiscoverTests/>.31 /// </summary>32 Task DiscoverTestsAsync(IEnumerable<string> sources, string runSettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler);33 /// <summary>34 /// Asynchronous equivalent of <see cref="ITranslationLayerRequestSender.StartTestRun(IEnumerable{string}, string, TestPlatformOptions, ITestRunEventsHandler)"/>.35 /// </summary>36 Task StartTestRunAsync(IEnumerable<string> sources, string runSettings, TestPlatformOptions options, ITestRunEventsHandler runEventsHandler);37 /// <summary>38 /// Asynchronous equivalent of <see cref="ITranslationLayerRequestSender.StartTestRun(System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase},string,Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestPlatformOptions,Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITestRunEventsHandler)"/>.39 /// </summary>40 Task StartTestRunAsync(IEnumerable<TestCase> testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler runEventsHandler);41 /// <summary>42 /// Asynchronous equivalent of <see cref="ITranslationLayerRequestSender.StartTestRunWithCustomHost(IEnumerable{string}, string, TestPlatformOptions, ITestRunEventsHandler, ITestHostLauncher)"/>.43 /// </summary>44 Task StartTestRunWithCustomHostAsync(IEnumerable<string> sources, string runSettings, TestPlatformOptions options, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customTestHostLauncher);45 /// <summary>46 /// Asynchronous equivalent of <see cref="ITranslationLayerRequestSender.StartTestRunWithCustomHost(System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase},string,Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestPlatformOptions,Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITestRunEventsHandler,Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces.ITestHostLauncher)"/>.47 /// </summary>48 Task StartTestRunWithCustomHostAsync(IEnumerable<TestCase> testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler runEventsHandler, ITestHostLauncher customTestHostLauncher);49 /// <summary>50 /// See <see cref="ITranslationLayerRequestSender.EndSession"/>.51 /// </summary>52 void EndSession();53 /// <summary>54 /// See <see cref="ITranslationLayerRequestSender.CancelTestRun"/>.55 /// </summary>56 void CancelTestRun();57 /// <summary>58 /// See <see cref="ITranslationLayerRequestSender.AbortTestRun"/>.59 /// </summary>60 void AbortTestRun();61 /// <summary>62 /// See <see cref="ITranslationLayerRequestSender.OnProcessExited"/>....

Full Screen

Full Screen

TestPlatform

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.Client;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;10{11 {12 static void Main(string[] args)13 {14 var testPlatform = new TestPlatform();15 var testRunCriteria = new TestRunCriteria(new List<string>() { "C:\\Users\\user\\Desktop\\testproject\\testproject\\bin\\Debug\\testproject.dll" }, "", TestFramework.Any, new Dictionary<string, string>());16 var testRunEventsHandler = new TestRunEventsHandler();17 testPlatform.RunTestRun(testRunCriteria, testRunEventsHandler);18 Console.ReadLine();19 }20 }21 {22 public void HandleLogMessage(TestMessageLevel level, string message)23 {24 Console.WriteLine("Log: " + message);25 }26 public void HandleRawMessage(string rawMessage)27 {28 Console.WriteLine("Raw: " + rawMessage);29 }30 public void HandleTestRunComplete(TestRunCompleteEventArgs completeArgs, CancellationToken cancellationToken, ITestRunStatisticsAggregator runStatsAggregator)31 {32 Console.WriteLine("Test run complete");33 }34 public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs, CancellationToken cancellationToken, ITestRunStatisticsAggregator runStatsAggregator)35 {36 Console.WriteLine("Test run stats change");37 }38 }39}

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