TestNG Tutorials 14: Can We Overload Methods In TestNG Class?

Hello Folks,

Method overloading is an important concept in Java. Can we create overloaded method in TestNG class. Let’s give it a try.

Overloaded TestNG class:

Create a testng.xml and run it:

Output:

You will get above exception in console because TestNG does not allow you to put any type of parameters to a TestNG annotated method. We will see about Dependency injection later.

Creating overloaded methods in TestNG using Data provider:

We can create overloaded methods in TestNG using Data provider. See a TestNG class below:

When you run above class as TestNG test, you will get output as:

 

Creating overloaded methods in TestNG using Parameters:

We can create overloaded methods in TestNG using Parameters. See a TestNG class below:

You need to create testng.xml with parameters tags as below:

When you run above testng.xml, you will get below output:

Hope you learnt new thing today.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium

1 thought on “TestNG Tutorials 14: Can We Overload Methods In TestNG Class?

Leave a Reply

Your email address will not be published. Required fields are marked *