How To Run Tests In Parallel

9 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.24
List Price:  €93.20
You save:  €27.96
£55.93
List Price:  £79.91
You save:  £23.97
CA$95.58
List Price:  CA$136.56
You save:  CA$40.97
A$107.13
List Price:  A$153.05
You save:  A$45.92
S$95.25
List Price:  S$136.08
You save:  S$40.82
HK$547.90
List Price:  HK$782.75
You save:  HK$234.85
CHF 63.85
List Price:  CHF 91.21
You save:  CHF 27.36
NOK kr770.13
List Price:  NOK kr1,100.23
You save:  NOK kr330.10
DKK kr486.51
List Price:  DKK kr695.05
You save:  DKK kr208.53
NZ$117.65
List Price:  NZ$168.07
You save:  NZ$50.42
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,679.19
List Price:  ৳10,970.75
You save:  ৳3,291.55
₹5,834.32
List Price:  ₹8,335.10
You save:  ₹2,500.78
RM333.81
List Price:  RM476.90
You save:  RM143.08
₦91,422.33
List Price:  ₦130,608.93
You save:  ₦39,186.60
₨19,487.31
List Price:  ₨27,840.21
You save:  ₨8,352.89
฿2,585.90
List Price:  ฿3,694.31
You save:  ฿1,108.40
₺2,277.50
List Price:  ₺3,253.72
You save:  ₺976.21
B$361.10
List Price:  B$515.88
You save:  B$154.78
R1,320.17
List Price:  R1,886.05
You save:  R565.87
Лв127.48
List Price:  Лв182.13
You save:  Лв54.64
₩96,293.43
List Price:  ₩137,567.94
You save:  ₩41,274.51
₪266.53
List Price:  ₪380.78
You save:  ₪114.24
₱4,038.21
List Price:  ₱5,769.12
You save:  ₱1,730.90
¥10,975.59
List Price:  ¥15,680.08
You save:  ¥4,704.49
MX$1,206.90
List Price:  MX$1,724.22
You save:  MX$517.31
QR255.26
List Price:  QR364.68
You save:  QR109.41
P965.80
List Price:  P1,379.77
You save:  P413.97
KSh9,448.65
List Price:  KSh13,498.65
You save:  KSh4,050
E£3,352.63
List Price:  E£4,789.68
You save:  E£1,437.04
ብር3,985.10
List Price:  ብር5,693.24
You save:  ብር1,708.14
Kz58,489.70
List Price:  Kz83,560.30
You save:  Kz25,070.60
CLP$66,385.51
List Price:  CLP$94,840.51
You save:  CLP$28,455
CN¥507.19
List Price:  CN¥724.59
You save:  CN¥217.40
RD$4,111.01
List Price:  RD$5,873.12
You save:  RD$1,762.11
DA9,398.61
List Price:  DA13,427.17
You save:  DA4,028.55
FJ$158.17
List Price:  FJ$225.97
You save:  FJ$67.79
Q544.39
List Price:  Q777.73
You save:  Q233.34
GY$14,639.41
List Price:  GY$20,914.34
You save:  GY$6,274.92
ISK kr9,791.60
List Price:  ISK kr13,988.60
You save:  ISK kr4,197
DH708.11
List Price:  DH1,011.63
You save:  DH303.52
L1,243.72
List Price:  L1,776.81
You save:  L533.09
ден4,016.98
List Price:  ден5,738.79
You save:  ден1,721.81
MOP$563.94
List Price:  MOP$805.67
You save:  MOP$241.72
N$1,340.22
List Price:  N$1,914.68
You save:  N$574.46
C$2,575.16
List Price:  C$3,678.96
You save:  C$1,103.79
रु9,316.74
List Price:  रु13,310.19
You save:  रु3,993.45
S/261.07
List Price:  S/372.97
You save:  S/111.90
K269.52
List Price:  K385.04
You save:  K115.52
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,842.03
List Price:  ZK2,631.59
You save:  ZK789.55
L324.63
List Price:  L463.78
You save:  L139.14
Kč1,640.70
List Price:  Kč2,343.96
You save:  Kč703.26
Ft25,605.88
List Price:  Ft36,581.40
You save:  Ft10,975.51
SEK kr762.91
List Price:  SEK kr1,089.92
You save:  SEK kr327.01
ARS$61,153.48
List Price:  ARS$87,365.86
You save:  ARS$26,212.38
Bs484.56
List Price:  Bs692.26
You save:  Bs207.70
COP$275,828.59
List Price:  COP$394,057.74
You save:  COP$118,229.14
₡35,172.98
List Price:  ₡50,249.28
You save:  ₡15,076.29
L1,727.65
List Price:  L2,468.18
You save:  L740.53
₲519,796.34
List Price:  ₲742,598.03
You save:  ₲222,801.68
$U2,684.12
List Price:  $U3,834.62
You save:  $U1,150.50
zł281.95
List Price:  zł402.81
You save:  zł120.85
Already have an account? Log In

Transcript

Hello all welcome back to the next one. In this one, we'll see how we can run test parallely using test engine. So what I have here is one class, which is test Angie underscore test parallel one. And then another class called test nj underscore test Palo Alto. That's about it. What I have here is two methods inside this one, test method one and test method two.

I'm printing one statement here. This is coming from test and G test parallel one test method one, then I'm sleeping for six seconds, about six seconds. And then I'm just printing more steps in this method. So basically, obviously, let's say the method takes about six seconds to run you might have a lot of steps and it might take about six seconds or maybe even less or more. But we are just taking six seconds for right now. Same thing for this method two and we have the same thing in the test parallel two class as well.

So we have two classes, and all done inside. Now let's take a look at the XML file. So I created one test and G dash parallel dot XML file here. And I named it as parallel test suite. And I actually created two different tests inside it. So this one is test one, and this runs parallel one class.

And this test is test two. And it runs test engine underscore parallel to class. So we have both the classes running in different test inside the same suite. Right. That's about it. So now, let me just try to run this one.

And let's see what happens. So run as test and G Suite. Bring it up so it runs and it's gonna take about six seconds, then it's gonna run tests to And then about six seconds, then it's gonna run test one from parallel to class right from here. And then again, it's waiting for six seconds always right because test engine execution is sequential. If we have multiple classes, multiple methods, everything is running sequentially. First method will complete then second method will start and then so on and so forth.

Right? So it ran for test, everything is fine, we can see here and everything is all good. Now let's see what if I want to run these methods parallely. I don't want to wait till first method is complete for the second method. And this is effective when you have methods not dependent on each other because if you have dependent methods and things really want the first method to complete before second method, children, then you should not do these kinds of things. But if you have like everything independent and you want to run these kind of things, or maybe there could be different configurations where you want to run test parallel one and test parallel to.

So let's assume that you are running this class. Here also, and you're running this class. Here all also. But both these tests are different configurations. Then also, you might want to run these test cases in parallel. But you will know based on your application these things.

So let's take a look how we can run them in parallel. So further suite, we have an attribute called parallel. So I'm going to type pa ra control space parallel. It gives me these options. So by default, it's none. And then I am going to delete this one and then hit Ctrl Space gives me all the options.

So we can run classes in bash. Last fall says none instances methods, or none. Or we can run test in parallel. So tests are these these tags, we can run test in parallel and true. So basically mostly use ones are either we can run classes in parallel, or methods and test. So these three are mostly used.

So right now I'm going to take an example of test. So parallel test. This one will help us running these tests in parallel. Another attribute that we can add here is thread count. So thread count is something it's by five by default, but we can do anything. So I'm going to take two right now.

So thread count is something which is by default, handled by test entity so we don't need to create any thread so don't even worry about creating threads and going into concurrency of Java. It is not at all related right now because testan g takes care of spanning multiple threats and it just does everything for us. So right now what we are concerned about is we can just based on our computer memory available CPU, we can provide number of threads, I'm just providing two right now, but we can actually give more also. So I saved it. And let me again, right click and run this file. And let's see the output.

So right now, both tests parallel to enter, spell one test method one started. So both started at the same time, and C, they finished at the same time, and you can see test parallel been already finished. And right now everything is finished. So basically, multiple methods started in parallel, right? And they finished at different times. So I'm just gonna run it again, because I want you to again, pay a little bit attention.

And let's run it as here and these two ones started together parallel one in Palo Alto test method one started together and then again, method two also started together and everything. So basically everything finished right now. But you guys could see that instead of waiting for six seconds it actually started test parallel to test method one. And then it started this parallel one test method one. Now you must be wondering why it did not start the test method to have the same class, right? Because it started test method one from different classes.

The reason is, we ran tests in parallel. So the test one it has back test and G underscore test parallel one class. So this started and in parallel, this class started. So it started both classes in parallel and whichever method could run it, ran it. That's how we Now what we can do here is, we can, if I provide this thing as classes, it's almost gonna be the same thing because we have both the classes and different tests right now let's take a look at methods What if I do run methods in parallel, so we can see a different output here. So just take a look at the current output right now.

Test method one started from both the classes. And this one ended and then test method two started from both the classes in parallel right. Now, let's right click, run as test in G Suite. And take a look. test method one and two started from the same class test, parallel one executed the steps and then from the same class test method one and two started. So basically, now the methods are running in parallel.

Instead of classes here we can see also will show the result execution. Once this is done, so parallel one testing just underscore test spell one classes done. And then this class started because this time these two methods started in parallel. So basically we can handle what we want to run in parallel. Either we can run tests in parallel or classes in parallel to run classes in parallel makes sense when we have more than one class here, then it makes sense. So the basic idea is still the same.

Whichever thing we want to run in parallel, it will run it run for us. So it depends on how we want to handle our test cases, whether we want to run different configurations in parallel, or we want to run different classes in parallel, or even different methods in parallel, but you have to be very careful that if you're running in parallel, things can get tricky. You might lose track of the logs, you might not figure out if a method is failed because of some other dependent method. So just be careful. This does not apply to every test suite. But it is still a feature if you have everything independent.

And if you want to run test configurations in parallel, this is really a very good feature. So that's about it. I'll see you in the next lectures and thanks for attending this one.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.