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
€66.52
List Price:  €95.03
You save:  €28.51
£55.29
List Price:  £78.99
You save:  £23.70
CA$98.01
List Price:  CA$140.02
You save:  CA$42.01
A$108.26
List Price:  A$154.67
You save:  A$46.40
S$94.28
List Price:  S$134.69
You save:  S$40.41
HK$544.68
List Price:  HK$778.14
You save:  HK$233.46
CHF 62.24
List Price:  CHF 88.92
You save:  CHF 26.68
NOK kr781.73
List Price:  NOK kr1,116.81
You save:  NOK kr335.07
DKK kr496.25
List Price:  DKK kr708.95
You save:  DKK kr212.70
NZ$119.48
List Price:  NZ$170.70
You save:  NZ$51.21
د.إ257.07
List Price:  د.إ367.25
You save:  د.إ110.18
৳8,430.24
List Price:  ৳12,043.71
You save:  ৳3,613.47
₹5,907.88
List Price:  ₹8,440.19
You save:  ₹2,532.31
RM313.59
List Price:  RM448
You save:  RM134.41
₦117,896.75
List Price:  ₦168,431.15
You save:  ₦50,534.40
₨19,601.13
List Price:  ₨28,002.81
You save:  ₨8,401.68
฿2,456.64
List Price:  ฿3,509.64
You save:  ฿1,053
₺2,405.01
List Price:  ₺3,435.88
You save:  ₺1,030.86
B$408.16
List Price:  B$583.12
You save:  B$174.95
R1,278.38
List Price:  R1,826.34
You save:  R547.95
Лв129.87
List Price:  Лв185.54
You save:  Лв55.66
₩98,547.64
List Price:  ₩140,788.38
You save:  ₩42,240.74
₪262.83
List Price:  ₪375.48
You save:  ₪112.65
₱4,119.38
List Price:  ₱5,885.08
You save:  ₱1,765.70
¥10,926.10
List Price:  ¥15,609.38
You save:  ¥4,683.28
MX$1,438.75
List Price:  MX$2,055.45
You save:  MX$616.69
QR257.25
List Price:  QR367.52
You save:  QR110.26
P957.42
List Price:  P1,367.80
You save:  P410.38
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,455.33
List Price:  E£4,936.40
You save:  E£1,481.07
ብር8,611.91
List Price:  ብር12,303.26
You save:  ብር3,691.35
Kz63,807.12
List Price:  Kz91,156.94
You save:  Kz27,349.81
CLP$68,583.90
List Price:  CLP$97,981.20
You save:  CLP$29,397.30
CN¥506.99
List Price:  CN¥724.30
You save:  CN¥217.31
RD$4,249.83
List Price:  RD$6,071.45
You save:  RD$1,821.61
DA9,380.49
List Price:  DA13,401.28
You save:  DA4,020.78
FJ$159.39
List Price:  FJ$227.72
You save:  FJ$68.32
Q545.12
List Price:  Q778.78
You save:  Q233.65
GY$14,759.55
List Price:  GY$21,085.97
You save:  GY$6,326.42
ISK kr9,759.40
List Price:  ISK kr13,942.60
You save:  ISK kr4,183.20
DH701.60
List Price:  DH1,002.33
You save:  DH300.73
L1,265.07
List Price:  L1,807.32
You save:  L542.25
ден4,092.25
List Price:  ден5,846.32
You save:  ден1,754.07
MOP$565.22
List Price:  MOP$807.49
You save:  MOP$242.27
N$1,267.59
List Price:  N$1,810.92
You save:  N$543.33
C$2,596.85
List Price:  C$3,709.94
You save:  C$1,113.09
रु9,521.24
List Price:  रु13,602.36
You save:  रु4,081.11
S/267.43
List Price:  S/382.06
You save:  S/114.63
K283.56
List Price:  K405.11
You save:  K121.54
SAR262.97
List Price:  SAR375.69
You save:  SAR112.72
ZK1,929.77
List Price:  ZK2,756.93
You save:  ZK827.16
L331.05
List Price:  L472.96
You save:  L141.90
Kč1,682
List Price:  Kč2,402.96
You save:  Kč720.96
Ft27,138
List Price:  Ft38,770.23
You save:  Ft11,632.23
SEK kr772.63
List Price:  SEK kr1,103.81
You save:  SEK kr331.17
ARS$69,869.10
List Price:  ARS$99,817.28
You save:  ARS$29,948.18
Bs487.60
List Price:  Bs696.60
You save:  Bs209
COP$315,227.33
List Price:  COP$450,344.06
You save:  COP$135,116.73
₡36,031.09
List Price:  ₡51,475.19
You save:  ₡15,444.10
L1,781.45
List Price:  L2,545.04
You save:  L763.59
₲550,680.18
List Price:  ₲786,719.69
You save:  ₲236,039.51
$U2,973.65
List Price:  $U4,248.26
You save:  $U1,274.60
zł288.46
List Price:  zł412.11
You save:  zł123.64
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.