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:
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.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning