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

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

TestPlatformTests.cs

Source:TestPlatformTests.cs Github

copy

Full Screen

...77 tp.ClearExtensions();78 this.extensionManager.Verify(em => em.ClearExtensions());79 }80 [TestMethod]81 public void CreateTestRunRequestShouldThrowExceptionIfNoTestHostproviderFound()82 {83 string settingsXml =84 @"<?xml version=""1.0"" encoding=""utf-8""?>85 <RunSettings>86 <RunConfiguration>87 <TargetFrameworkVersion>.NETPortable,Version=v4.5</TargetFrameworkVersion>88 </RunConfiguration>89 </RunSettings>";90 var testRunCriteria = new TestRunCriteria(new List<string> { @"x:dummy\foo.dll" }, 10, false, settingsXml, TimeSpan.Zero);91 var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, null);92 bool exceptionThrown = false;93 try94 {95 tp.CreateTestRunRequest(this.mockRequestData.Object, testRunCriteria);96 }97 catch(TestPlatformException ex)98 {99 exceptionThrown = true;100 Assert.AreEqual("No suitable test runtime provider found for this run.", ex.Message);101 }102 Assert.IsTrue(exceptionThrown, "TestPlatformException should get thrown");103 }104 [TestMethod]105 public void CreateTestRunRequestShouldUpdateLoggerExtensionWhenDesingModeIsFalseForRunAll()106 {107 var additionalExtensions = new List<string> { "foo.TestLogger.dll", "Joo.TestLogger.dll" };108 this.mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny<string>())).Returns(true);109 this.mockFileHelper.Setup(fh => fh.EnumerateFiles(It.IsAny<string>(), System.IO.SearchOption.TopDirectoryOnly, It.IsAny<string[]>())).Returns(additionalExtensions);110 this.executionManager.Setup(dm => dm.Initialize()).Verifiable();111 string settingsXml =112 @"<?xml version=""1.0"" encoding=""utf-8""?>113 <RunSettings>114 <RunConfiguration>115 <DesignMode>false</DesignMode>116 </RunConfiguration>117 </RunSettings>";118 var testRunCriteria = new TestRunCriteria(new List<string> { @"x:dummy\foo.dll" }, 10, false, settingsXml, TimeSpan.Zero);119 this.hostManager.Setup(hm => hm.GetTestSources(testRunCriteria.Sources))120 .Returns(testRunCriteria.Sources);121 this.testEngine.Setup(te => te.GetExecutionManager(this.mockRequestData.Object, this.hostManager.Object, It.IsAny<TestRunCriteria>())).Returns(this.executionManager.Object);122 this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object);123 var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, this.hostManager.Object);124 var testRunRequest = tp.CreateTestRunRequest(this.mockRequestData.Object, testRunCriteria);125 this.extensionManager.Verify(em => em.UseAdditionalExtensions(additionalExtensions, false));126 }127 [TestMethod]128 public void CreateTestRunRequestShouldUpdateLoggerExtensionWhenDesignModeIsFalseForRunSelected()129 {130 var additionalExtensions = new List<string> { "foo.TestLogger.dll", "Joo.TestLogger.dll" };131 this.mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny<string>())).Returns(true);132 this.mockFileHelper.Setup(fh => fh.EnumerateFiles(It.IsAny<string>(), System.IO.SearchOption.TopDirectoryOnly, It.IsAny<string[]>())).Returns(additionalExtensions);133 this.executionManager.Setup(dm => dm.Initialize()).Verifiable();134 string settingsXml =135 @"<?xml version=""1.0"" encoding=""utf-8""?>136 <RunSettings>137 <RunConfiguration>138 <DesignMode>false</DesignMode>139 </RunConfiguration>140 </RunSettings>";141 var testRunCriteria = new TestRunCriteria(new List<TestCase> { new TestCase("dll1.class1.test1", new Uri("hello://x/"), "xyz\\1.dll") }, 10, false, settingsXml);142 this.testEngine.Setup(te => te.GetExecutionManager(this.mockRequestData.Object, this.hostManager.Object, It.IsAny<TestRunCriteria>())).Returns(this.executionManager.Object);143 this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object);144 var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, this.hostManager.Object);145 var testRunRequest = tp.CreateTestRunRequest(this.mockRequestData.Object, testRunCriteria);146 this.extensionManager.Verify(em => em.UseAdditionalExtensions(additionalExtensions, false));147 }148 [TestMethod]149 public void CreateTestRunRequestShouldNotUpdateTestSourcesIfSelectedTestAreRun()150 {151 var additionalExtensions = new List<string> { "foo.TestLogger.dll", "Joo.TestLogger.dll" };152 this.mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny<string>())).Returns(true);153 this.mockFileHelper.Setup(fh => fh.EnumerateFiles(It.IsAny<string>(), System.IO.SearchOption.TopDirectoryOnly, It.IsAny<string[]>())).Returns(additionalExtensions);154 this.executionManager.Setup(dm => dm.Initialize()).Verifiable();155 string settingsXml =156 @"<?xml version=""1.0"" encoding=""utf-8""?>157 <RunSettings>158 <RunConfiguration>159 <DesignMode>false</DesignMode>160 </RunConfiguration>161 </RunSettings>";162 var testRunCriteria = new TestRunCriteria(new List<TestCase> { new TestCase("dll1.class1.test1", new Uri("hello://x/"), "xyz\\1.dll") }, 10, false, settingsXml);163 this.hostManager.Setup(hm => hm.GetTestSources(It.IsAny<IEnumerable<string>>()))164 .Returns(new List<string> { "xyz\\1.dll" });165 this.testEngine.Setup(te => te.GetExecutionManager(this.mockRequestData.Object, this.hostManager.Object, It.IsAny<TestRunCriteria>())).Returns(this.executionManager.Object);166 this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object);167 var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, this.hostManager.Object);168 tp.CreateTestRunRequest(this.mockRequestData.Object, testRunCriteria);169 this.extensionManager.Verify(em => em.UseAdditionalExtensions(additionalExtensions, false));170 this.hostManager.Verify(hm => hm.GetTestSources(It.IsAny<IEnumerable<string>>()), Times.Never);171 }172 [TestMethod]173 public void CreateTestRunRequestShouldInitializeManagersAndCreateTestRunRequestWithSpecifiedCriteria()174 {175 this.executionManager.Setup(dm => dm.Initialize()).Verifiable();176 this.testEngine.Setup(te => te.GetExecutionManager(this.mockRequestData.Object, this.hostManager.Object, It.IsAny<TestRunCriteria>())).Returns(this.executionManager.Object);177 this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object);178 var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object);179 var testRunCriteria = new TestRunCriteria(new List<string> { "foo" }, 10);180 this.hostManager.Setup(hm => hm.GetTestSources(testRunCriteria.Sources))181 .Returns(testRunCriteria.Sources);182 var testRunRequest = tp.CreateTestRunRequest(this.mockRequestData.Object, testRunCriteria);183 var actualTestRunRequest = testRunRequest as TestRunRequest;184 this.hostManager.Verify(hm => hm.Initialize(It.IsAny<TestSessionMessageLogger>(), It.IsAny<string>()), Times.Once);185 this.executionManager.Verify(em => em.Initialize(), Times.Once);186 Assert.AreEqual(testRunCriteria, actualTestRunRequest.TestRunCriteria);187 }188 [TestMethod]189 public void CreateTestRunRequestShouldSetCustomHostLauncherOnEngineDefaultLauncherIfSpecified()190 {191 var mockCustomLauncher = new Mock<ITestHostLauncher>();192 this.executionManager.Setup(dm => dm.Initialize()).Verifiable();193 this.testEngine.Setup(te => te.GetExecutionManager(this.mockRequestData.Object, this.hostManager.Object, It.IsAny<TestRunCriteria>())).Returns(this.executionManager.Object);194 this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object);195 var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object);196 var testRunCriteria = new TestRunCriteria(new List<string> { "foo" }, 10, false, null, TimeSpan.Zero, mockCustomLauncher.Object);197 this.hostManager.Setup(hm => hm.GetTestSources(testRunCriteria.Sources))198 .Returns(testRunCriteria.Sources);199 var testRunRequest = tp.CreateTestRunRequest(this.mockRequestData.Object, testRunCriteria);200 var actualTestRunRequest = testRunRequest as TestRunRequest;201 Assert.AreEqual(testRunCriteria, actualTestRunRequest.TestRunCriteria);202 this.hostManager.Verify(hl => hl.SetCustomLauncher(mockCustomLauncher.Object), Times.Once);203 }204 [TestMethod]205 public void CreateTestRunRequestThrowsIfTestRunCriteriaIsNull()206 {207 var tp = new TestPlatform();208 Assert.ThrowsException<ArgumentNullException>(() => tp.CreateTestRunRequest(this.mockRequestData.Object, null));209 }210 [TestMethod]211 public void CreateDiscoveryRequestShouldThrowExceptionIfNoTestHostproviderFound()212 {213 string settingsXml =214 @"<?xml version=""1.0"" encoding=""utf-8""?>215 <RunSettings>216 <RunConfiguration>217 <TargetFrameworkVersion>.NETPortable,Version=v4.5</TargetFrameworkVersion>218 </RunConfiguration>219 </RunSettings>";220 var discoveryCriteria = new DiscoveryCriteria(new List<string> { @"x:dummy\foo.dll" }, 1, settingsXml);221 var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, null);222 bool exceptionThrown = false;...

Full Screen

Full Screen

RunTestsArgumentProcessorTests.cs

Source:RunTestsArgumentProcessorTests.cs Github

copy

Full Screen

...121 {122 var mockTestPlatform = new Mock<ITestPlatform>();123 var mockTestRunRequest = new Mock<ITestRunRequest>();124 mockTestRunRequest.Setup(tr => tr.ExecuteAsync()).Throws(new TestPlatformException("DummyTestPlatformException"));125 mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny<IRequestData>(), It.IsAny<TestRunCriteria>())).Returns(mockTestRunRequest.Object);126 this.ResetAndAddSourceToCommandLineOptions();127 var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestLoggerManager.Instance, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask);128 var executor = GetExecutor(testRequestManager);129 ArgumentProcessorResult argumentProcessorResult = executor.Execute();130 Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult);131 }132 [TestMethod]133 public void ExecutorExecuteShouldCatchSettingsExceptionAndReturnFail()134 {135 var mockTestPlatform = new Mock<ITestPlatform>();136 var mockTestRunRequest = new Mock<ITestRunRequest>();137 mockTestRunRequest.Setup(tr => tr.ExecuteAsync()).Throws(new SettingsException("DummySettingsException"));138 mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny<IRequestData>(), It.IsAny<TestRunCriteria>())).Returns(mockTestRunRequest.Object);139 this.ResetAndAddSourceToCommandLineOptions();140 var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestLoggerManager.Instance, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask);141 var executor = GetExecutor(testRequestManager);142 ArgumentProcessorResult argumentProcessorResult = executor.Execute();143 Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult);144 }145 [TestMethod]146 public void ExecutorExecuteShouldCatchInvalidOperationExceptionAndReturnFail()147 {148 var mockTestPlatform = new Mock<ITestPlatform>();149 var mockTestRunRequest = new Mock<ITestRunRequest>();150 mockTestRunRequest.Setup(tr => tr.ExecuteAsync()).Throws(new InvalidOperationException("DummyInvalidOperationException"));151 mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny<IRequestData>(), It.IsAny<TestRunCriteria>())).Returns(mockTestRunRequest.Object);152 this.ResetAndAddSourceToCommandLineOptions();153 var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestLoggerManager.Instance, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask);154 var executor = GetExecutor(testRequestManager);155 ArgumentProcessorResult argumentProcessorResult = executor.Execute();156 Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult);157 }158 [TestMethod]159 public void ExecutorExecuteShouldThrowOtherExceptions()160 {161 var mockTestPlatform = new Mock<ITestPlatform>();162 var mockTestRunRequest = new Mock<ITestRunRequest>();163 mockTestRunRequest.Setup(tr => tr.ExecuteAsync()).Throws(new Exception("DummyException"));164 mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny<IRequestData>(), It.IsAny<TestRunCriteria>())).Returns(mockTestRunRequest.Object);165 this.ResetAndAddSourceToCommandLineOptions();166 var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestLoggerManager.Instance, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask);167 var executor = GetExecutor(testRequestManager);168 Assert.ThrowsException<Exception>(() => executor.Execute());169 }170 [TestMethod]171 public void ExecutorExecuteShouldForListOfTestsReturnSuccess()172 {173 var mockTestRunRequest = new Mock<ITestRunRequest>();174 var result = this.RunRunArgumentProcessorExecuteWithMockSetup(mockTestRunRequest.Object);175 mockTestRunRequest.Verify(tr => tr.ExecuteAsync(), Times.Once);176 Assert.AreEqual(ArgumentProcessorResult.Success, result);177 }178 [TestMethod]179 public void TestRunRequestManagerShouldInstrumentExecutionRequestStart()180 {181 var mockTestRunRequest = new Mock<ITestRunRequest>();182 var result = this.RunRunArgumentProcessorExecuteWithMockSetup(mockTestRunRequest.Object);183 this.mockTestPlatformEventSource.Verify(x => x.ExecutionRequestStart(), Times.Once);184 }185 [TestMethod]186 public void TestRunRequestManagerShouldInstrumentExecutionRequestStop()187 {188 var mockTestRunRequest = new Mock<ITestRunRequest>();189 var result = this.RunRunArgumentProcessorExecuteWithMockSetup(mockTestRunRequest.Object);190 this.mockTestPlatformEventSource.Verify(x => x.ExecutionRequestStop(), Times.Once);191 }192 #endregion193 private ArgumentProcessorResult RunRunArgumentProcessorExecuteWithMockSetup(ITestRunRequest testRunRequest)194 {195 var mockTestPlatform = new Mock<ITestPlatform>();196 var mockConsoleOutput = new Mock<IOutput>();197 List<TestCase> list = new List<TestCase>();198 list.Add(new TestCase("Test1", new Uri("http://FooTestUri1"), "Source1"));199 list.Add(new TestCase("Test2", new Uri("http://FooTestUri2"), "Source2"));200 var mockTestRunStats = new Mock<ITestRunStatistics>();201 var args = new TestRunCompleteEventArgs(mockTestRunStats.Object, false, false, null, null, new TimeSpan());202 mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny<IRequestData>(), It.IsAny<TestRunCriteria>())).Returns(testRunRequest);203 this.ResetAndAddSourceToCommandLineOptions();204 var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestLoggerManager.Instance, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask);205 var executor = GetExecutor(testRequestManager);206 return executor.Execute();207 }208 private void ResetAndAddSourceToCommandLineOptions()209 {210 CommandLineOptions.Instance.Reset();211 CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object;212 CommandLineOptions.Instance.AddSource(this.dummyTestFilePath);213 }214 public static void SetupMockExtensions()215 {216 SetupMockExtensions(() => { });...

Full Screen

Full Screen

CreateTestRunRequest

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 request = TestPlatform.CreateTestRunRequest();15 </RunSettings>";16 var sources = new List<string>();17 sources.Add(@"C:\Users\user\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.dll");18 request.RunTests(sources, runSettings, new TestPlatformOptions());19 request.WaitForCompletion();20 }21 }22}23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28using Microsoft.VisualStudio.TestPlatform.Client;29using Microsoft.VisualStudio.TestPlatform.ObjectModel;30using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;31using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;32{33 {34 static void Main(string[] args)35 {36 var request = TestPlatform.CreateTestRunRequest();

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