You can use the Parallel Test functionality of MsTest to run multiple test cases in parallel.
We can set tests to run at the Assembly level or at the Method level.
Make sure the WebDriver object is not declared as static to run the test parallelly.
From two methods we can enable this parallelization.
We can set tests to run at the Assembly level or at the Method level.
Make sure the WebDriver object is not declared as static to run the test parallelly.
From two methods we can enable this parallelization.
- From Test Class
- From Test settings
First, we have to install the following Nuget packages of MsTest in our project
- MSTest.TestFramework
From Test Class
[assembly: Parallelize(Workers = 6, Scope = ExecutionScope.MethodLevel)]
This will enable parallelization in the whole project even if the code snippet if given in any one Test Class.
From Test Settings
In alternative from Test Class, we can set parallelization from Test settings.
1 2 3 4 5 6 7 8 9 10 11 12 | <Parallelize> <Workers>3</Workers> <Scope>MethodLevel</Scope> </Parallelize> <!-- <TestTimeout>1000000</TestTimeout> --> </MSTest> <RunConfiguration> <MaxCpuCount>0</MaxCpuCount> <DisableParallelization>false</DisableParallelization> <!-- Path relative to solution directory --> <ResultsDirectory>.\TestResults</ResultsDirectory> </RunConfiguration> |
Sample test setting XML file for MSTest including test run parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <RunSettings> <Description> Run a UI test locally or on a VM test agent. </Description> <Execution> </Execution> <!-- MSTest adapter --> <MSTest> <MapInconclusiveToFailed>true</MapInconclusiveToFailed> <CaptureTraceOutput>true</CaptureTraceOutput> <DeleteDeploymentDirectoryAfterTestRunIsComplete>false</DeleteDeploymentDirectoryAfterTestRunIsComplete> <DeploymentEnabled>false</DeploymentEnabled> <Parallelize> <Workers>3</Workers> <Scope>MethodLevel</Scope> </Parallelize> <!-- <TestTimeout>1000000</TestTimeout> --> </MSTest> <RunConfiguration> <MaxCpuCount>0</MaxCpuCount> <DisableParallelization>false</DisableParallelization> <!-- Path relative to solution directory --> <ResultsDirectory>.\TestResults</ResultsDirectory> </RunConfiguration> <TestRunParameters> <Parameter name="isAzureHostedTest" value="True" /> <Parameter name="isHostedSetupTest" value="True" /> <Parameter name="Environment" value="Dev" /> <Parameter name="Browser" value="chrome+headless" /> </TestRunParameters> </RunSettings> |
No comments:
Post a Comment