ITestResult Interface

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. In this one, we will take a look at I test result interface. So let me just bring up Eclipse. And I've created a class called test mg I test result demo. And I think it's here somewhere. So in the class, we have test method one, test method two and one after method.

And I'll explain you what all means. One thing I want to mention is please do not use the exact results from test and D like do not just use a test result. Always append something or add something on before because if we use the same names from an existing library, we might have issues when we run the code. So now let's take a look. Other thing is I'm using assert here so please make sure that we use a third from test Angie because lots of people have j unit libraries also And then you will have issues. So what we have right now here is we have a print statement inside test method one that it's running test method one, and then we are asserting false.

So basically, we are asserting false to assert true. So which means test method one is going to fail. And in test method to again a print statement, and we're asserting true to assert true. So which means test method two is going to be successful. Now what we want to do here is we want something or some way by which we know what was the result of the previous method, which was run. So let's say if test method burn was run, I want to know what was the result like if it was successful, or it failed.

So for those things, test engine has provided an interface called I test result. And this can be used to figure those things out, figure out the status of the last run test method and this interface is like a listener, it's kind of listening every time. And after every test method is run, it knows the status of the last run method. So we can use it to fetch the status. Now, we can use it in combination with after method, because after method is always run after every test method. So basically, if we use the itis listener here, we will be able to fetch out the result, right.

So to use the eye test result, what we want to do here is we will provide an argument to the after method here, so I test result, and I'm just gonna name the argument as test result. So I test result is the type and test result is our name of the argument. I'm going to hover the mouse on it, and I'm gonna click on Import itis result from our dot test, mg, all Make sure we import the correct thing. Once we have it, we can actually kind of bring the status. So let me just say, See, so, and I'm gonna print maybe the method name first right now. So we'll see we can use it in different ways.

So test result, dot, get method, and dot get method name. So if we see this, basically, test result, and this guy returns, it says it returns this method. This the test method, this result represents. So basically, the get method is the test method in which the result is representing. And then get method name. It returns the method name.

And it's usually Yeah, it's obviously the gonna be the method name. In which we ran the test cases. So that's what we are running right now. And we can also get the status and do those things. So let me first run it right now. And we will just go step by step.

So run as test in G test. And we can see a pair that test method one is failed, because we expected true, but we know that we provided false so it's gonna fail. And test method two is successful. In console we can see running test method one is coming from test method. And this is coming from after method, test method, one, the name of the method and then running test method two, and test method to the name of the method. So basically, that's what we printed here, right.

So we know that in after method, we could fetch the name of the test method, which was run just before it so first time it returned us test method one and second time test method two Which is pretty cool. And we can use it in lots of different ways. So now let me just do one more thing. So I'm going to do F. So based on the status of the last test case, we can print few things, or we can do some actions. Or if we want to do something based on the previous result, let's say my test was failed, and I want to take a screenshot, or my test was successful, and I want to report something I want to enter something into the database. I mean, anything you can do, depending on your application or your needs, but the important part is we have the capabilities to take actions based on the result of the last test case.

So I'm going to say, test result, dot get status. So this thing is gonna return us so you can see on the left, the status of this result using one of the constants above so basically, get status equals two Then constant we want to use here is I test result. And that should be exactly same right is result dot failure. So let's say I'm based on the failure, I'm gonna print something. So let me just copy this thing here. And I can add a few more things to make it a little easier to understand.

So because it's on the test case, fail, I'm printing here failed, plus the name of the method that failed. So basically, that's what I'm going to say. And I'm going to use the same thing one more if condition. And in this one, we can say I test result dot started success. So basically, we wonder one from success. And here I'm gonna say successful and the name of the method.

I want to show you what way to get the name of the method. So basically, instead of doing get method dot method name, we can just say get name. And if I hover my mouse, you can read the description. So let me actually bring it on little bit up. So you can read the description it says the name of this test result, and typically it is identical to the name of the method. So we can just do this as well.

Now we have both the test methods, and we have the after method, and we are printing the results based on it right? So let me right click it run as test in G test. And let's see the output. So running test method one, and failed test method one, running test method two and successful test method two. So these two lines are coming from our after method, which is using the eye test method. Right.

And the further ones this is from the test engine report, which by default happens and this exception or error is from the failed test case. And we already know about this one. So it's all expected. Let's take a look at the import statements. import statement for this is our dot test nj dot test result. So that's about it.

It can be used in many ways, as we discussed. So please go ahead, download the code file, practice it. Let me know if you have any questions and I'll see you in the next lectures. Thanks for attending this one. Thanks.

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.