BeforeSuite And AfterSuite Annotations

8 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. Since we have now already learned, what is the test suite and how we can club classes to make a test Wait, let's take a mod together. Since we have a test suite now similar to before class and after class, there could be requirements that we want to execute before all of the test cases start. And there could be requirements that we want to clean up the whole system after all the test cases are run. exactly similar to before class and after class right before class has things which we want to set up for that particular class and after classes has those stuff, which you want to clean up from that particular class. We can have similar requirements for the complete test suite for the combination of test classes.

Now is the time to learn what is a before suite and after suite annotation. So what I've done here is to simplify some stuff. I have copied the These tests class one and class two to a new package called regression suite. It's these are the same classes, I just modified the print statements to be a little cleaner instead of big lines, just small lines, create a new test with the XML suite and named it as regression dash suite dot XML. So we know that we can actually name it anything and updated the package name here to refer to the correct classes. And then I created a base package and there's nothing inside it.

We'll just talk about it why we created since we have some common stuff right now that we are talking about, we want to execute something common before all the suite is gonna get run. And we want to clean up our system after the complete test suite is done executing. We want a place where we want to put all the common stuff. We don't want to put that common stuff in every class. We don't want to unnecessarily bulk up those classes. That's why we will create a base test class and inherited that base class in every test class.

So all the common stuff is written at a single place. That's why I created a package called base. Inside it, I'll say new, and other test engine class. Click Next. And here we will call it as base test suite. I'm going to import this thing before sweet after suede.

And let's say we have a few common things before in that we want to put in before class and after class for the basis we're also so understand these things as something specific to all the test classes there is something common that you want to execute in before class. Those common things Also, you don't want to put in every single class, it's better to put in a common place. Maybe for a test class one, there is a common thing and which is common to test class two, and there are some separate stuff also. So those common things can be put into the base test suite. And then the separate specific stuff to test class one can be put in the before class of test class one. So we can actually select these also and click Finish.

It will create a base test wait for us, I can format it. I can delete that. Add the rate test annotation because there will be no test case inside this class. We only want to put the common stuff here. I can do command shift or Ctrl Shift o to clean up the import statements. And that's about it.

Now I'm gonna just copy some print statement here. So we can type it here. So it's just easy to understand from where our print statements are coming. Obviously, for an application, you will have the test code the common stuff here right now we are just printing it out because we are more interested in learning the concept, then we are testing any application. So this thing is from base test suite. It's a before class.

And we'll put the similar thing in after class as well. And we'll put the similar thing in before sweet and after sweet. So, these annotations these methods, they will only execute once before both the test classes execute not once after every before every test class only once and then it will execute as class one then it will execute as class two and then after a suite will get executed. So this guy is after and sweet, not the class. So that's about it. Now what we want to do here is we want to extend our test classes to use the base test suite.

So type extends, this is from inheritance base test suite. And as soon as I did that, you should notice that it imported based test suite here. And this is very important important. If we don't import this, it will not know about the base test suite. Right. Let me do it manually here in test class to so you guys can see it.

So this is import from base dot base test suite. This is how we import it. And here we will say extends base test suite. So controlspace is our shortcut for the IntelliSense and all done. Now both the test classes are set up I'm just going to right click the regression suite dot XML and run this and then we're going to take a look at the output. So run as test in G Suite.

And we can see here that regression test suite from regression package both the test class one and class two are executed successfully. Let's go to console and let's take a look at the output. So from based as to it before, so it is executed, then from based test suite before class is executed. Then starts their first test class. From first class before class is executed and before method and test method burned and after method, then again before method and test method to the after method and test class one and share and it executes after class. Then notice that the base test suite after classes executed and then based test suite before classes.

Execute. Again, but there is no after suite executed from base test suite. So it's all going before class and after class executed. And then test class two started before class before method, test method one after method before method test method two after method and then test class two ends after class is executed, then from base test suite after class is executed. And finally, from base test suite after a suite is executed. So, before suite and after suite execute only once and in between all the test classes will get executed.

So this is the purpose of before suite and after suite annotation. This was the right time to talk about them because we already saw how we run the test suites in combination, how we run all the test classes in combination using a test suite. So that's about it. Please practice it and let me know if you have any questions and I'll see you in the next lecture. Thanks We're ending 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.