Make Selenium Easy

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

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

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

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.