Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun
ParallelProxyExecutionManager.cs
Source:ParallelProxyExecutionManager.cs  
...69            this.skipDefaultAdapters = skipDefaultAdapters;70            this.DoActionOnAllManagers((proxyManager) => proxyManager.Initialize(skipDefaultAdapters), doActionsInParallel: true);71            this.IsInitialized = true;72        }73        public int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)74        {75            this.hasSpecificTestsRun = testRunCriteria.HasSpecificTests;76            this.actualTestRunCriteria = testRunCriteria;77            if (this.hasSpecificTestsRun)78            {79                var testCasesBySource = new Dictionary<string, List<TestCase>>();80                foreach (var test in testRunCriteria.Tests)81                {82                    if (!testCasesBySource.ContainsKey(test.Source))83                    {84                        testCasesBySource.Add(test.Source, new List<TestCase>());85                    }86                    testCasesBySource[test.Source].Add(test);87                }88                // Do not use "Dictionary.ValueCollection.Enumerator" - it becomes nondeterministic once we go out of scope of this method89                // Use "ToArray" to copy ValueColleciton to a simple array and use it's enumerator90                // Set the enumerator for parallel yielding of testCases91                // Whenever a concurrent executor becomes free, it picks up the next set of testCases using this enumerator92                var testCaseLists = testCasesBySource.Values.ToArray();93                this.testCaseListEnumerator = testCaseLists.GetEnumerator();94                this.availableTestSources = testCaseLists.Length;95            }96            else97            {98                // Set the enumerator for parallel yielding of sources99                // Whenever a concurrent executor becomes free, it picks up the next source using this enumerator100                this.sourceEnumerator = testRunCriteria.Sources.GetEnumerator();101                this.availableTestSources = testRunCriteria.Sources.Count();102            }103            if (EqtTrace.IsVerboseEnabled)104            {105                EqtTrace.Verbose("ParallelProxyExecutionManager: Start execution. Total sources: " + this.availableTestSources);106            }107            return this.StartTestRunPrivate(eventHandler);108        }109        public void Abort(ITestRunEventsHandler runEventsHandler)110        {111            // Test platform initiated abort.112            abortRequested = true;113            this.DoActionOnAllManagers((proxyManager) => proxyManager.Abort(runEventsHandler), doActionsInParallel: true);114        }115        public void Cancel(ITestRunEventsHandler runEventsHandler)116        {117            this.DoActionOnAllManagers((proxyManager) => proxyManager.Cancel(runEventsHandler), doActionsInParallel: true);118        }119        public void Close()120        {121            this.DoActionOnAllManagers(proxyManager => proxyManager.Close(), doActionsInParallel: true);122        }123        #endregion124        #region IParallelProxyExecutionManager methods125        /// <summary>126        /// Handles Partial Run Complete event coming from a specific concurrent proxy execution manager127        /// Each concurrent proxy execution manager will signal the parallel execution manager when its complete128        /// </summary>129        /// <param name="proxyExecutionManager">Concurrent Execution manager that completed the run</param>130        /// <param name="testRunCompleteArgs">RunCompleteArgs for the concurrent run</param>131        /// <param name="lastChunkArgs">LastChunk testresults for the concurrent run</param>132        /// <param name="runContextAttachments">RunAttachments for the concurrent run</param>133        /// <param name="executorUris">ExecutorURIs of the adapters involved in executing the tests</param>134        /// <returns>True if parallel run is complete</returns>135        public bool HandlePartialRunComplete(136            IProxyExecutionManager proxyExecutionManager,137            TestRunCompleteEventArgs testRunCompleteArgs,138            TestRunChangedEventArgs lastChunkArgs,139            ICollection<AttachmentSet> runContextAttachments,140            ICollection<string> executorUris)141        {142            var allRunsCompleted = false;143            lock (this.executionStatusLockObject)144            {145                // Each concurrent Executor calls this method 146                // So, we need to keep track of total run complete calls147                this.runCompletedClients++;148                if (testRunCompleteArgs.IsCanceled || abortRequested)149                {150                    allRunsCompleted = this.runCompletedClients == this.runStartedClients;151                }152                else153                {154                    allRunsCompleted = this.runCompletedClients == this.availableTestSources;155                }156                if (EqtTrace.IsVerboseEnabled)157                {158                    EqtTrace.Verbose("ParallelProxyExecutionManager: HandlePartialRunComplete: Total completed clients = {0}, Run complete = {1}, Run canceled: {2}.", this.runCompletedClients, allRunsCompleted, testRunCompleteArgs.IsCanceled);159                }160            }161            // verify that all executors are done with the execution and there are no more sources/testcases to execute162            if (allRunsCompleted)163            {164                // Reset enumerators165                this.sourceEnumerator = null;166                this.testCaseListEnumerator = null;167                this.currentRunDataAggregator = null;168                this.currentRunEventsHandler = null;169                // Dispose concurrent executors170                // Do not do the cleanup task in the current thread as we will unnecessarily add to execution time171                this.UpdateParallelLevel(0);172                return true;173            }174            if (EqtTrace.IsVerboseEnabled)175            {176                EqtTrace.Verbose("ParallelProxyExecutionManager: HandlePartialRunComplete: Replace execution manager. Shared: {0}, Aborted: {1}.", this.SharedHosts, testRunCompleteArgs.IsAborted);177            }178            this.RemoveManager(proxyExecutionManager);179            proxyExecutionManager = CreateNewConcurrentManager();180            var parallelEventsHandler = this.GetEventsHandler(proxyExecutionManager);181            this.AddManager(proxyExecutionManager, parallelEventsHandler);182            // If cancel is triggered for any one run or abort is requested by test platform, there is no reason to fetch next source183            // and queue another test run184            if (!testRunCompleteArgs.IsCanceled && !abortRequested)185            {186                this.StartTestRunOnConcurrentManager(proxyExecutionManager);187            }188            return false;189        }190        #endregion191        private int StartTestRunPrivate(ITestRunEventsHandler runEventsHandler)192        {193            this.currentRunEventsHandler = runEventsHandler;194            // Reset the run complete data195            this.runCompletedClients = 0;196            // One data aggregator per parallel run197            this.currentRunDataAggregator = new ParallelRunDataAggregator();198            foreach (var concurrentManager in this.GetConcurrentManagerInstances())199            {200                var parallelEventsHandler = this.GetEventsHandler(concurrentManager);201                this.UpdateHandlerForManager(concurrentManager, parallelEventsHandler);202                this.StartTestRunOnConcurrentManager(concurrentManager);203            }204            return 1;205        }206        private ParallelRunEventsHandler GetEventsHandler(IProxyExecutionManager concurrentManager)207        {208            if (concurrentManager is ProxyExecutionManagerWithDataCollection)209            {210                var concurrentManagerWithDataCollection = concurrentManager as ProxyExecutionManagerWithDataCollection;211                // TODO : use TestPluginCache to iterate over all IDataCollectorAttachments212                var attachmentsProcessingManager = new TestRunAttachmentsProcessingManager(TestPlatformEventSource.Instance, new CodeCoverageDataAttachmentsHandler());213                return new ParallelDataCollectionEventsHandler(214                            this.requestData,215                            concurrentManagerWithDataCollection,216                            this.currentRunEventsHandler,217                            this,218                            this.currentRunDataAggregator,219                            attachmentsProcessingManager,220                            concurrentManagerWithDataCollection.CancellationToken);221            }222            return new ParallelRunEventsHandler(223                        this.requestData,224                        concurrentManager,225                        this.currentRunEventsHandler,226                        this,227                        this.currentRunDataAggregator);228        }229        /// <summary>230        /// Triggers the execution for the next data object on the concurrent executor231        /// Each concurrent executor calls this method, once its completed working on previous data232        /// </summary>233        /// <param name="proxyExecutionManager">Proxy execution manager instance.</param>234        /// <returns>True, if execution triggered</returns>235        private void StartTestRunOnConcurrentManager(IProxyExecutionManager proxyExecutionManager)236        {237            TestRunCriteria testRunCriteria = null;238            if (!this.hasSpecificTestsRun)239            {240                if (this.TryFetchNextSource(this.sourceEnumerator, out string nextSource))241                {242                    EqtTrace.Info("ProxyParallelExecutionManager: Triggering test run for next source: {0}", nextSource);243                    testRunCriteria = new TestRunCriteria(new[] { nextSource }, this.actualTestRunCriteria);244                }245            }246            else247            {248                if (this.TryFetchNextSource(this.testCaseListEnumerator, out List<TestCase> nextSetOfTests))249                {250                    EqtTrace.Info("ProxyParallelExecutionManager: Triggering test run for next source: {0}", nextSetOfTests?.FirstOrDefault()?.Source);251                    testRunCriteria = new TestRunCriteria(nextSetOfTests, this.actualTestRunCriteria);252                }253            }254            if (testRunCriteria != null)255            {256                if (!proxyExecutionManager.IsInitialized)257                {258                    proxyExecutionManager.Initialize(this.skipDefaultAdapters);259                }260                Task.Run(() =>261                {262                    Interlocked.Increment(ref this.runStartedClients);263                    if (EqtTrace.IsVerboseEnabled)264                    {265                        EqtTrace.Verbose("ParallelProxyExecutionManager: Execution started. Started clients: " + this.runStartedClients);266                    }267                    proxyExecutionManager.StartTestRun(testRunCriteria, this.GetHandlerForGivenManager(proxyExecutionManager));268                })269                .ContinueWith(t =>270                {271                    // Just in case, the actual execution couldn't start for an instance. Ensure that272                    // we call execution complete since we have already fetched a source. Otherwise273                    // execution will not terminate274                    if (EqtTrace.IsErrorEnabled)275                    {276                        EqtTrace.Error("ParallelProxyExecutionManager: Failed to trigger execution. Exception: " + t.Exception);277                    }278                    var handler = this.GetHandlerForGivenManager(proxyExecutionManager);279                    var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = t.Exception.ToString() };280                    handler.HandleRawMessage(this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload));281                    handler.HandleLogMessage(TestMessageLevel.Error, t.Exception.ToString());282                    // Send a run complete to caller. Similar logic is also used in ProxyExecutionManager.StartTestRun283                    // Differences:284                    // Aborted is sent to allow the current execution manager replaced with another instance285                    // Ensure that the test run aggregator in parallel run events handler doesn't add these statistics286                    // (since the test run didn't even start)287                    var completeArgs = new TestRunCompleteEventArgs(null, false, true, null, new Collection<AttachmentSet>(), TimeSpan.Zero);288                    handler.HandleTestRunComplete(completeArgs, null, null, null);289                },290                TaskContinuationOptions.OnlyOnFaulted);291            }292            if (EqtTrace.IsVerboseEnabled)293            {294                EqtTrace.Verbose("ProxyParallelExecutionManager: No sources available for execution.");295            }296        }...ProxyExecutionManager.cs
Source:ProxyExecutionManager.cs  
...76        /// </summary>77        /// <param name="testRunCriteria"> The settings/options for the test run. </param>78        /// <param name="eventHandler"> EventHandler for handling execution events from Engine. </param>79        /// <returns> The process id of the runner executing tests. </returns>80        public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)81        {82            this.baseTestRunEventsHandler = eventHandler;83            try84            {85                if (EqtTrace.IsVerboseEnabled)86                {87                    EqtTrace.Verbose("ProxyExecutionManager: Test host is always Lazy initialize.");88                }89                var testPackages = new List<string>(testRunCriteria.HasSpecificSources ? testRunCriteria.Sources :90                                                    // If the test execution is with a test filter, group them by sources91                                                    testRunCriteria.Tests.GroupBy(tc => tc.Source).Select(g => g.Key));92                this.isCommunicationEstablished = this.SetupChannel(testPackages, this.cancellationTokenSource.Token);93                if (this.isCommunicationEstablished)94                {95                    if (this.cancellationTokenSource.IsCancellationRequested)96                    {97                        if (EqtTrace.IsVerboseEnabled)98                        {99                            EqtTrace.Verbose("ProxyExecutionManager.StartTestRun: Canceling the current run after getting cancelation request.");100                        }101                        throw new TestPlatformException(Resources.Resources.CancelationRequested);102                    }103                    this.InitializeExtensions(testPackages);104                    // This code should be in sync with InProcessProxyExecutionManager.StartTestRun executionContext105                    var executionContext = new TestExecutionContext(106                        testRunCriteria.FrequencyOfRunStatsChangeEvent,107                        testRunCriteria.RunStatsChangeEventTimeout,108                        inIsolation: false,109                        keepAlive: testRunCriteria.KeepAlive,110                        isDataCollectionEnabled: false,111                        areTestCaseLevelEventsRequired: false,112                        hasTestRun: true,113                        isDebug: (testRunCriteria.TestHostLauncher != null && testRunCriteria.TestHostLauncher.IsDebug),114                        testCaseFilter: testRunCriteria.TestCaseFilter,115                        filterOptions: testRunCriteria.FilterOptions);116                    // This is workaround for the bug https://github.com/Microsoft/vstest/issues/970117                    var runsettings = this.RemoveNodesFromRunsettingsIfRequired(testRunCriteria.TestRunSettings, (testMessageLevel, message) => { this.LogMessage(testMessageLevel, message); });118                    if (testRunCriteria.HasSpecificSources)119                    {120                        var runRequest = testRunCriteria.CreateTestRunCriteriaForSources(testHostManager, runsettings, executionContext, testPackages);121                        this.RequestSender.StartTestRun(runRequest, this);122                    }123                    else124                    {125                        var runRequest = testRunCriteria.CreateTestRunCriteriaForTests(testHostManager, runsettings, executionContext, testPackages);126                        this.RequestSender.StartTestRun(runRequest, this);127                    }128                }129            }130            catch (Exception exception)131            {132                EqtTrace.Error("ProxyExecutionManager.StartTestRun: Failed to start test run: {0}", exception);133                this.LogMessage(TestMessageLevel.Error, exception.Message);134                // Send a run complete to caller. Similar logic is also used in ParallelProxyExecutionManager.StartTestRunOnConcurrentManager135                // Aborted is `true`: in case of parallel run (or non shared host), an aborted message ensures another execution manager136                // created to replace the current one. This will help if the current execution manager is aborted due to irreparable error137                // and the test host is lost as well.138                var completeArgs = new TestRunCompleteEventArgs(null, false, true, exception, new Collection<AttachmentSet>(), TimeSpan.Zero);139                this.HandleTestRunComplete(completeArgs, null, null, null);140            }141            return 0;142        }143        /// <summary>144        /// Cancels the test run.145        /// </summary>146        public virtual void Cancel()147        {148            // Cancel fast, try to stop testhost deployment/launch...StartTestRun
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11    {12        public void TestPlatformTest1()13        {14            var executionManager = new ProxyExecutionManager();15            var requestSender = new ProxyExecutionManager();16            var testRunCriteria = new TestRunCriteria(new List<string>() { "test.dll" }, 1, false, new TestPlatformOptions(), new TestLoggerEvents());17            var runEventsHandler = new TestRunEventsHandler();18            var testRunRequest = new TestRunRequest(testRunCriteria, runEventsHandler);19            executionManager.StartTestRun(testRunRequest);20        }21    }22}23using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;24using Microsoft.VisualStudio.TestPlatform.ObjectModel;25using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;26using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;27using System;28using System.Collections.Generic;29using System.Linq;30using System.Text;31using System.Threading.Tasks;32{33    {34        public void TestPlatformTest2()35        {36            var executionManager = new ProxyExecutionManager();37            var requestSender = new ProxyExecutionManager();38            var testRunCriteria = new TestRunCriteria(new List<string>() { "test.dll" }, 1, false, new TestPlatformOptions(), new TestLoggerEvents());39            var runEventsHandler = new TestRunEventsHandler();40            var testRunRequest = new TestRunRequest(testRunCriteria, runEventsHandler);41            executionManager.StartTestRun(testRunRequest);42            executionManager.StopTestRun();43        }44    }45}46using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;47using Microsoft.VisualStudio.TestPlatform.ObjectModel;48using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;49using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;50using System;51using System.Collections.Generic;52using System.Linq;53using System.Text;54using System.Threading.Tasks;55{56    {StartTestRun
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;8using Microsoft.VisualStudio.TestPlatform.ObjectModel;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;10using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;11using System.Threading;12{13    {14        static void Main(string[] args)15        {16            ProxyExecutionManager executionManager = new ProxyExecutionManager();17            ITestRunRequest testRunRequest = executionManager.StartTestRun(new TestRunCriteria(new List<string>() { "C:\\Users\\Administrator\\Desktop\\TestProject1.dll" }, 1, false, new TestPlatformOptions(), new TestRunCriteria.TestHostLauncherCallback(null)), new TestRunEventsHandler());18            testRunRequest.WaitForCompletion();19            var results = testRunRequest.GetTestRunStatistics();20            Console.WriteLine("Total tests: " + results.TotalTests);21            Console.WriteLine("Passed tests: " + results.TotalPassedTests);22            Console.WriteLine("Failed tests: " + results.TotalFailedTests);23            Console.ReadKey();24        }25    }26    {27        public void HandleLogMessage(TestMessageLevel level, string message)28        {29            if (level == TestMessageLevel.Error)30            {31                Console.WriteLine("Error: " + message);32            }33            else if (level == TestMessageLevel.Warning)34            {35                Console.WriteLine("Warning: " + message);36            }37            {38                Console.WriteLine("Information: " + message);39            }40        }41        public void HandleRawMessage(string rawMessage)42        {43            Console.WriteLine("Raw message: " + rawMessage);44        }45        public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteEventsArgs, CancellationToken cancellationToken)46        {47            Console.WriteLine("Test run complete");48        }49        public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedEventsArgs)50        {51            Console.WriteLine("Test run stats change");52        }53    }54}55using System;56using System.Collections.Generic;57using System.Linq;StartTestRun
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11    {12        static void Main(string[] args)13        {14            ProxyExecutionManager p = new ProxyExecutionManager();15            var t = p.StartTestRun(new List<string>(), new Dictionary<string, string>(), new TestPlatformOptions(), new TestRunCriteria(new List<string>(), 1), new ConsoleRunEventsHandler());16            Console.WriteLine(t);17            Console.ReadLine();18        }19    }20}21using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;22using Microsoft.VisualStudio.TestPlatform.ObjectModel;23using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;24using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;25using System;26using System.Collections.Generic;27using System.Linq;28using System.Text;29using System.Threading.Tasks;30{31    {32        static void Main(string[] args)33        {34            ProxyExecutionManager p = new ProxyExecutionManager();35            var t = p.RunTests(new List<string>(), new Dictionary<string, string>(), new TestPlatformOptions(), new TestRunCriteria(new List<string>(), 1), new ConsoleRunEventsHandler());36            Console.WriteLine(t);37            Console.ReadLine();38        }39    }40}41using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;42using Microsoft.VisualStudio.TestPlatform.ObjectModel;43using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;44using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;45using System;46using System.Collections.Generic;47using System.Linq;48using System.Text;49using System.Threading.Tasks;50{51    {52        static void Main(string[] args)53        {54            ProxyExecutionManager p = new ProxyExecutionManager();55            var t = p.RunTests(new List<string>(), new Dictionary<string, string>(), new TestPlatformOptions(), new TestRunCriteria(new List<string>(), 1), new ConsoleRunEventsHandler());56            Console.WriteLine(t);57            Console.ReadLine();58        }59    }60}StartTestRun
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;8using Microsoft.VisualStudio.TestPlatform.ObjectModel;9{10    {11        static void Main(string[] args)12        {13            ProxyExecutionManager proxyExecutionManager = new ProxyExecutionManager();14            proxyExecutionManager.StartTestRun(new TestRunCriteria(new List<string> { "test.dll" }, 1, false, new TestPlatformOptions(), null, null), new TestRunEventsHandler(), new ConsoleLogger());15            Console.ReadLine();16        }17    }18}StartTestRun
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;7{8    {9        static void Main(string[] args)10        {11            ProxyExecutionManager proxyExecutionManager = new ProxyExecutionManager();12            proxyExecutionManager.StartTestRun();13        }14    }15}StartTestRun
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using System.Collections.Generic;5using System.Linq;6using System.Reflection;7using System.Threading.Tasks;8using System;9using System.IO;10using System.Security;11using System.Security.Permissions;12using System.Security.Policy;13using System.Runtime.Remoting;14using System.Runtime.Remoting.Channels;15using System.Runtime.Remoting.Channels.Ipc;16using System.Runtime.Remoting.Channels.Tcp;17{18    {19        static void Main(string[] args)20        {21            var channel = new IpcChannel("console");22            ChannelServices.RegisterChannel(channel, false);23            var executionManager = new ProxyExecutionManager();24            var runRequest = executionManager.CreateTestRunRequest(new TestRunCriteria(new List<string>() { "C:\\Users\\username\\source\\repos\\UnitTestProject1\\bin\\Debug\\netcoreapp2.1\\UnitTestProject1.dll" }, 1, false, new TestPlatformOptions(), new TestFilter()));25            var runTask = runRequest.ExecuteAsync();26            runTask.Wait();27            var testRunResult = runTask.Result;28            Console.WriteLine("Test run completed: {0}", testRunResult.IsAborted ? "Aborted" : "Completed");29            Console.WriteLine("Passed tests: {0}", testRunResult.TestRunStatistics[TestCaseResultStatus.Passed]);30            Console.WriteLine("Failed tests: {0}", testRunResult.TestRunStatistics[TestCaseResultStatus.Failed]);31            Console.WriteLine("Skipped tests: {0}", testRunResult.TestRunStatistics[TestCaseResultStatus.Skipped]);32            Console.WriteLine("Total tests: {0}", testRunResult.TestRunStatistics[TestCaseResultStatus.Passed] + testRunResult.TestRunStatistics[TestCaseResultStatus.Failed] + testRunResult.TestRunStatistics[TestCaseResultStatus.Skipped]);33            Console.ReadLine();34        }35    }36}StartTestRun
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Threading.Tasks;4using Microsoft.VisualStudio.TestPlatform.Common;5using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;6using Microsoft.VisualStudio.TestPlatform.Common.Logging;7using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;8using Microsoft.VisualStudio.TestPlatform.ObjectModel;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;10using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol;11{12    {13        static void Main(string[] args)14        {15            var testRunCriteria = new TestRunCriteria(new List<string> { "C:\\Users\\test\\Desktop\\UnitTestProject1.dll" }, 1, false, null, null, null, null);16            var proxyExecutionManager = new ProxyExecutionManager();17            var proxyExecutionManagerType = proxyExecutionManager.GetType();18            var startTestRunMethod = proxyExecutionManagerType.GetMethod("StartTestRun", new Type[] { typeof(TestRunCriteria), typeof(ITestRunEventsHandler), typeof(ICollection<string>), typeof(bool), typeof(bool) });19            var testRunEventsHandler = new TestRunEventsHandler();20            startTestRunMethod.Invoke(proxyExecutionManager, new object[] { testRunCriteria, testRunEventsHandler, null, false, false });21        }22    }23    {24        public void HandleLogMessage(TestMessageLevel level, string message)25        {26            Console.WriteLine(message);27        }28        public void HandleRawMessage(string rawMessage)29        {30            Console.WriteLine(rawMessage);31        }32        public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteEventArgs, TestRunChangedEventArgs testRunChangedEventArgs, ICollection<AttachmentSet> executorUris, TimeSpan elapsedTime)33        {34            Console.WriteLine("Test run complete");35        }36        public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedEventArgs)37        {38            Console.WriteLine("Test run stats change");39        }40        public void HandleTestRunUpdate(TestRunChangedEventArgs testRunChangedEventArgs)41        {42            Console.WriteLine("Test run update");43        }44    }45}46using System;47using System.Collections.Generic;48using System.Threading.Tasks;49using Microsoft.VisualStudio.TestPlatform.Common;50using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;51using Microsoft.VisualStudio.TestPlatform.Common.Logging;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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
