We have seen how inheritance works in TestNg classes in this post. In this post, we will see how overriding works in inherited TestNG classes.
Create a super class as below:
Now create a sub class where we will override one method from super class as below:
Let’s run subclass as a testng test:
You can see that only overridden methods in subclass got executed. In this post , we learnt that TestNG prioritized and execute methods of super class and subclass separately. But if some methods are overridden, only overridden method will be executed and parent method of super class will be ignored. If you have better understanding of overriding concept in java, then it is similar to calling super class method using sub class reference.
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 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through 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