Make Selenium Easy

TestNG Tutorials 20: Overriding Of Test Methods In TestNG Class

Hello Folks,

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.

Table of Contents

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

2 thoughts on “TestNG Tutorials 20: Overriding Of Test Methods In TestNG Class

  1. System.out.println(“hello”); is working under @Test method. but

    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;

    is not working ashowing an error.

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.

TestNG Tutorials 20: Overriding Of Test Methods In TestNG Class

by Amod Mahajan time to read: 1 min
%d bloggers like this: