• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - Jira Selenium Protractor Testing SDLC Agile Methodology

Java Selenium Tutorial & Testing Interview Questions

  • Home
  • Interview Questions
  • Java
  • Java Programs
  • Test Cases
  • Selenium
  • Manual Testing
  • Difference
  • Search
SoftwareTestingo » Selenium » Selenium Tutorial » TestNG Method Overriding – With Sample Example

TestNG Method Overriding – With Sample Example

Last Updated on: November 30, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • TestNG Method Overriding Example

TestNG Method Overriding: Earlier, we have seen how we can achieve method overloading in a TestNG class, and similarly, in this post, we are going to see how we can make method overriding in a testNG class.

As we all know about method overriding is nothing but creating a method in child class which is already a similar method in the parent class is called method overriding. If you want to know the complete post about this, you can use this method overriding the link.

TestNG Method Overriding Example

So let us discuss how we can achieve method overriding in Java:

First Creat a superclass like below:

package InheritanceInTestNG;
import org.testng.annotations.Test;
public class SuperTestNgClass 
{

   @Test
   public void superTestNgMethod()
   {
      System.out.println(“Super testng method”);
   }

   @Test
   public void superTestNgAnotherMethod()
   {
      System.out.println(“Super testng Another method”);
   }
}

Create another child class like below:

package InheritanceInTestNG;
import org.testng.annotations.Test;
public class SubTestNGClass extends SuperTestNgClass
{

   // Overriding super class testng methods
   @Test
   public void superTestNgMethod()
   {
      System.out.println("Super testng method overrriden in sub class");
   }

   // Method of sub class
   @Test
   public void subTestNgMethod()
   {
      System.out.println("Sub testng method");
   }
}

Now create a testng.xml file for the child class and run that. If you take a look at the output, then you will find out that it will execute all the methods of child class with the overridden method.

In our earlier discussion, we have seen that TestNG prioritizes and executes the test cases if we run separately both super and subclasses. But if we override, then all methods of subclass with the overridden method will be executed, but the parent method of superclass will be ignored.

Source: link

    Filed Under: Selenium Tutorial

    Reader Interactions

    Leave a Reply Cancel reply

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

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Tutorials Important Links

    • Software Testing Jobs
    • Manual Testing Tutorial
    • Selenium Tutorial
    • Core Java Tutorial
    • TestNG Tutorial
    • Java Programs
    • Selenium Programs
    • Manual Test Cases
    • Interview Tips
    • Contact US
    • www.softwaretestingo.com

    Important Links

    • Software Testing Interview Questions
    • Agile Interview Questions
    • Manual Testing Interview Questions
    • Testing Interview Questions
    • Selenium Interview Questions
    • Selenium Real Time Interview Questions
    • Selenium WebDriver Interview Questions
    • Automation Framework Interview Questions
    • Appium Interview Questions
    • TestNG Interview Questions
    • Java Interview Questions
    • Core Java Interview Questions

    Categories

    Copyright © 2021 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy