parallel testing in junit

Solutions on MaxInterview for parallel testing in junit by the best coders in the world

showing results for - "parallel testing in junit"
Rafael
15 Mar 2017
1To run parallel testing in Junit
2We are using maven-surefire plugin
3in pom.xml file.
4We can specify how many threads we
5want to run as at the same time.
6
7We also have to make some changes 
8in Driver class. We need to use 
9"ThreadLocal<WebDriver> instead of
10"WebDriver" Because "WebDriver" 
11generates only a single WebDriver object, 
12but "ThreadLocal<WebDriver>" generates
13multiple browser to run parallel testing.
14
15
16 <testFailureIgnore>TRUE</testFailureIgnore>
17     <parallel>METHODS</parallel>
18     <threadCount>40</threadCount> 
19     <forkCount>2C</forkCount>
20     <perCoreThreadCount>false</perCoreThreadCount>
21     <include>**/*Runner*.java</include>
22
23*Runner* - any test class Contains Runner
24 Runner* - any test class starts with Runner
25*Runner  - any test class ends with Runner 
26
27PerCoreThreadCount: set false it will
28try to match number of threads with number
29of CPU cores. Regardsless on threadCount value.
30
Ashley
30 Mar 2018
1If we use JUNIT, we can use maven plugins to run tests in parallel. 
2In maven-surefire-plugin, we can specify how many threads we want to open 
3at the same time.
4
5<plugin>
6	<groupId>org.apache.maven.plugins</groupId>
7	<artifactId>maven-surefire-plugin</artifactId>
8	<version>2.18.1</version>
9	<configuration>
10		<parallel>classes</parallel>  ==> you can choose classes or methods
11		<threadCount>5</threadCount>  ==> how many browser will be launched
12			<includes>					  
13				<includetest1.java</include>   
14				<includetest2.java</include>
15				<includetest3.java</include>
16				<includetest4.java</include>
17			</includes>
18		<testFailureIgnore>true</testFailureIgnore>
19	</configuration>
20</plugin>
21
22We also have to make some changes in Driver class. We need to use 
23"ThreadLocal<WebDriver> driverPool" instead of "WebDriver driver". 
24Because "WebDriver" generates only a single WebDriver object, 
25whereas "ThreadLocal<WebDriver>" generates multiple browser to run 
26parallel testing.  
27
28In TestNG it is very easy and efficient to perform
29