Hi Instructor,
I am confused with the following code. What is called? I was watching an video on ExtentReport. In the video, you created a new class called ExtentManager and in that you have created a method like this:
static ExtentReports reports;
public static ExtentReports getReports()
{
if(reports == null)
{
reports = new ExtentReports();
}
What is this concept? I know we can assign a reference to the object of a class.
For instance,
ExtentReports e = new ExtentReports();
Do you have any examples on ExtentReports getReports()? Or Can you provide me with a simple example?
Thanks,
Instructor
Ashish Thakur Replied on 04/11/2020
Many test classes will be there. Each test class should come in 1 single report.
So 1 single report should have multiple test cases. This means just one object of report class should be formed. That is the reason, We have written code like that
Yes, I understood that we are creating a method that will include reports of all tests.
I am confused about this line you wrote in your code
public static ExtentReports getReports()
ClassName with method name.
Suppose I have a Dog class and when I want to assign a value to the reference variable after creating an object,
int height;
Dog d = new Dog();
d.height = 5;
But in your code for the method you are writing like
public static ExtentReports getReports()
I am confused with this function declaration. Can you please help me understand.
Instructor
Ashish Thakur Replied on 04/11/2020
public static int add() -> returns integer
public static ExtentReports getReports() -> returns object reference of extent reports
So in function ExtentReports is the return type
Got it. That was very simple. :)