TestNG Reporters And Logs

TestNG Complete Bootcamp For Beginners: Novice To Ninja TestNG Reporter Logs and HTML Reports
12 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.85
List Price:  €94.08
You save:  €28.22
£54.88
List Price:  £78.41
You save:  £23.52
CA$97.62
List Price:  CA$139.46
You save:  CA$41.84
A$107.14
List Price:  A$153.07
You save:  A$45.92
S$93.58
List Price:  S$133.69
You save:  S$40.11
HK$544.41
List Price:  HK$777.76
You save:  HK$233.35
CHF 61.77
List Price:  CHF 88.25
You save:  CHF 26.47
NOK kr774.53
List Price:  NOK kr1,106.52
You save:  NOK kr331.99
DKK kr491.29
List Price:  DKK kr701.88
You save:  DKK kr210.58
NZ$117.97
List Price:  NZ$168.54
You save:  NZ$50.56
د.إ257.07
List Price:  د.إ367.25
You save:  د.إ110.18
৳8,356.44
List Price:  ৳11,938.29
You save:  ৳3,581.84
₹5,906.12
List Price:  ₹8,437.68
You save:  ₹2,531.55
RM311.31
List Price:  RM444.75
You save:  RM133.44
₦117,341.73
List Price:  ₦167,638.23
You save:  ₦50,296.50
₨19,435.08
List Price:  ₨27,765.59
You save:  ₨8,330.51
฿2,425.53
List Price:  ฿3,465.20
You save:  ฿1,039.66
₺2,405.72
List Price:  ₺3,436.89
You save:  ₺1,031.17
B$402.27
List Price:  B$574.70
You save:  B$172.42
R1,258.03
List Price:  R1,797.26
You save:  R539.23
Лв128.99
List Price:  Лв184.28
You save:  Лв55.29
₩97,811.61
List Price:  ₩139,736.86
You save:  ₩41,925.25
₪263.26
List Price:  ₪376.11
You save:  ₪112.84
₱4,099.48
List Price:  ₱5,856.66
You save:  ₱1,757.17
¥10,841.47
List Price:  ¥15,488.48
You save:  ¥4,647.01
MX$1,431.90
List Price:  MX$2,045.66
You save:  MX$613.75
QR254.94
List Price:  QR364.22
You save:  QR109.27
P951.38
List Price:  P1,359.18
You save:  P407.79
KSh9,042.70
List Price:  KSh12,918.70
You save:  KSh3,876
E£3,449.01
List Price:  E£4,927.37
You save:  E£1,478.36
ብር8,642.24
List Price:  ብር12,346.59
You save:  ብር3,704.35
Kz63,935.86
List Price:  Kz91,340.86
You save:  Kz27,405
CLP$68,957.33
List Price:  CLP$98,514.70
You save:  CLP$29,557.36
CN¥504.52
List Price:  CN¥720.77
You save:  CN¥216.25
RD$4,213.97
List Price:  RD$6,020.22
You save:  RD$1,806.24
DA9,349.80
List Price:  DA13,357.43
You save:  DA4,007.63
FJ$158.35
List Price:  FJ$226.22
You save:  FJ$67.87
Q540.36
List Price:  Q771.98
You save:  Q231.61
GY$14,629.10
List Price:  GY$20,899.61
You save:  GY$6,270.51
ISK kr9,727.21
List Price:  ISK kr13,896.61
You save:  ISK kr4,169.40
DH693.72
List Price:  DH991.08
You save:  DH297.35
L1,261.20
List Price:  L1,801.79
You save:  L540.59
ден4,052.03
List Price:  ден5,788.86
You save:  ден1,736.83
MOP$560.29
List Price:  MOP$800.45
You save:  MOP$240.16
N$1,263.45
List Price:  N$1,805.01
You save:  N$541.55
C$2,573.57
List Price:  C$3,676.69
You save:  C$1,103.11
रु9,448.55
List Price:  रु13,498.52
You save:  रु4,049.96
S/264.27
List Price:  S/377.55
You save:  S/113.27
K280.92
List Price:  K401.34
You save:  K120.41
SAR262.94
List Price:  SAR375.65
You save:  SAR112.70
ZK1,903.83
List Price:  ZK2,719.87
You save:  ZK816.04
L327.74
List Price:  L468.23
You save:  L140.48
Kč1,667.45
List Price:  Kč2,382.17
You save:  Kč714.72
Ft26,926.18
List Price:  Ft38,467.63
You save:  Ft11,541.44
SEK kr762.04
List Price:  SEK kr1,088.67
You save:  SEK kr326.63
ARS$69,832.85
List Price:  ARS$99,765.49
You save:  ARS$29,932.64
Bs484.91
List Price:  Bs692.76
You save:  Bs207.85
COP$304,883.34
List Price:  COP$435,566.30
You save:  COP$130,682.96
₡35,784.92
List Price:  ₡51,123.51
You save:  ₡15,338.58
L1,764.81
List Price:  L2,521.27
You save:  L756.45
₲546,392.79
List Price:  ₲780,594.59
You save:  ₲234,201.79
$U2,951.08
List Price:  $U4,216.01
You save:  $U1,264.93
zł285.94
List Price:  zł408.51
You save:  zł122.56
Already have an account? Log In

Transcript

Hello all welcome back to the next one. In this one we'll talk about reporters in test engine. And also how can we generate HTML reports using test engine. So reporters are nothing but kind of for replacement of logs for Jay. I mean, the log for j is a different tool or API's that we usually use to write logs, like whatever statements that we want to print. Usually we don't use this system dot out dot print ln, right?

We have different login mechanism in our application, and the most popular one is log for j or maybe lock for j two. So we can log statements in console or we can log statements in external files also. But test engine also provides one more mechanism to log their statements and that is known as reporter The only benefit is the state That we log using the reporter goes into the reports that are generated by test Angie automatically. So that's the only benefit I see. But I don't see it as a replacement of log for se because I would still recommend you guys to continue using whatever you're using. It completely depends on you what you want to use in your application.

I generally prefer lock for j two. But reporter is also a good stuff. Basically what you can do is you can do a mix and match of both things. For all individual actions, you can probably use log for J. And then for high level actions like test started, test, entered or maybe test finished or maybe some high level actions. You can use reporter so you can see them in test injury reports, if at all you are using custom reports.

So let's take a look. What I have here is I have a test engineer Under score reports and logs file created, it's just a usual file that we always create. It has methods like before class after class. Before method after method, and three test methods I created test method one, it's gonna be normal successful test case, test method two, I'm intentionally failing this test method and test method three. It is also a normal test case. But what happens is it depends on test method two.

So if test method two fails, then we're going to have test method three skip. I'm intentionally doing it so we can have three different kinds of results. One is successful one is fail and one escape so we can see all of them in the report. So till now we were just using System dot out dot print ln statements with reporter what we can do here is I'm going to first show you the import statement. So this is the import statement. Import or dot test nj dot reporter, make sure that you have the correct import statement.

Once you have that, then let me just let me just delete it and write it again for you. So we will say reporter dot log. And these are different overloads. I'm going to use the second one, and I'll show you what that is. So it accepts two arguments. The first one is string s, which is the message that we want to log.

And the second one is log to standard out. Which means if we want to print the same message on the console or not standard out is the console. So we can use the same message from here. And I'm just gonna use the same message and this manifests a false. Let's see the difference. I'm gonna just say false and right click This file, run it as test in G test.

And it ran the test case, we can see three tests run one failed one skip and one was successful we can see it here as well. And here it printed out once this runs before every class and then the, this runs before every method. So, before every class has printed only once, even though we have two statements here, right? Even though we have two statements it only printed once. The reason is, we said false to standard out if I provided true it's gone up printed twice first from the System dot out dot print ln and then second from the reporter dot log. So again, run it as test and the test.

And now we can see this runs once before class is printed twice. And we got it by right. So what we can do here We can actually replace the System dot out dot print ln statements with the reporter dot lot, so I'm just gonna maybe copy all of them. And we can use the second overload and everything. So just cut it from there, paste it. And this one can always be kept true, because we always want to log.

Currently at least for the demo purpose, we always want to log to the console so we can see the output really handy. If we don't print it here, we will not be able to see it in the console. So it's just a good idea to keep it there. So let's replace all these messages. I'm just gonna show you that. Even if we remove every System dot out dot print ln statement.

We are still good to go. We can achieve the same thing. Using the reporter logs, so let's just quickly try to replace them. And all these are done, only three methods are left. So let me just quickly copy them here so we can save some time. And copy these messages.

Delete System dot out dot print ln statement and copy this message. Delete this one. And we are just left with the last statement. So we'll just put it here. And that's about it. So now we're not using any of the System dot out dot print ln statements.

And we are just using reporter dot log and we can run As test in G test, and we can still see everything getting printed up here, because we are using the true as the argument. Now the other part of the question is generating the HTML reports. What do we have to do to generate the reports? The good part is we don't have to do anything. Tests engine takes care of it automatically. And it does it.

The only thing that we want to do here is we cannot generate reports. If we right click the file and run the code, we have to create an XML file that sn G Suite file, and then run that as a test in G Suite. And then it will automatically generate the report for us. So let me just do that. So I created this XML file. It's again the same file there is no difference.

I just change the class name. If I run this file, right click, run as test in G Suite, you will see the difference. So just pay attention on the left side in the project and you We'll see one test output folder. So it has run, everything is run successfully. And when I refresh the project, right click the project, refresh it. There we go, we see this test dash output folder.

And if I expand it, I can see a lot of different things here. So there are two reports. One is email, double dash report dot html, and the other is index dot HTML. We can open them from here as well. If I double click it, it will open in Eclipse. But since they are HTML files, we should actually go to the location.

And we should be able to open it on the browser as a normal file also. And if you don't know where these files are located on your system, just right click this one or maybe just right click your project and see the properties you will see the location and current windows also you will still be able to see the location. So you need to figure out where you created this one. So Have it on documents workspace personal. And there is the project that I created test engine tutorial. So what I'm gonna do here is I'm gonna do two documents, and my workspace personal.

And then test engine tutorial. This is the project. So everything is right here inside it, I can go to the source folder, I can figure out all the packages. Everything is there, I can copy any code file also from here. So here is the test output folder. I'm going to double click it, it's going to present me all the files.

So these are the two files email label report dot html. And this opens in Firefox by default or any other browser that you have. So this is the report kind of report we have. And the good part is now since we had three different kind of test cases, it shows us three different places. So this one failed test method and it's in red, the one which was skipped is grayed out test method three and the one which was successful is increasing test methods and we can see some error messages. Also for test method two, we can click on them to actually reach where these methods are.

So this one is for test method one and everything is successful, there is no other messages. So it's all good. And here in the summary, it shows the test name was application test, and it's coming from the XML file. And then how many are successful, how many has cabe and how many are fail and how much total time it took. So it's a pretty decent report and the one we opened was email label report dot html. And now let's quickly take a look at the index dot HTML.

So this one is a different format, but essentially gives us the same thing. So you can see three methods here one failed, one skipped one was successful. You can click on the test method to show you the errors. You can click on test method three, I'll show you what happens. With that, and so basically, it's already showing the name of the class as method two is a test method, three cells, everything is shown. And then what was successful when I clicked show so we can hide and show right?

When I click Show, it shows me for the test method one also, the other part here interesting is this report on output. So if I click on this, it tells me the output from the reporter. So test method one. This was the statement that be printed. From test method two, this was the statement that we printed, so anything that we put in using the reporter log, these statements are shown in the report up here. Yes, but we don't see anything from the before class before method and those things.

Because there isn't it it is only kind of concerned about the test methods. So we see the statements only from the testament. That's here. So there we can see the report output also. So pretty much kind of a decent report. It's not really fancy, but it's still a decent report to start with, you can kind of use it.

And that's about it. So the good part is we don't need to do anything extra. It's it just comes by default. It just comes with the default settings test and it does everything for us. So it's still quite handy. So that's about it.

I will say please go ahead, download the code file practice a little bit. And let me know if you have any questions. 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.