Make Selenium Easy

TestNG Tutorials 5: How To Create And Run A TestNG Class

Hello Folks,

In this post, we will see some basics implementation of TestNG.

A class is called TestNG class if it has annotations provided by TestNG. TestNG provides an annotation called “Test” which you need to use for any method which has some business logic to verify. When you add this “Test” annotation, you DON’T Require to include “public static void main(String args[])” method in your class. Main method is starting point of execution of a java program. But when you add “Test” annotation with methods, JVM run those methods directly.

Suppose, you need to verify below sceanrios:

  1. Are String “Selenium WebDriver” and “Selenium” equal?
  2. Is variable ‘x’ is greater than zero?

You will create two methods for each scenario and need to add “@Test” annotation.

Steps to be followed:

  1. Create a plain java class.
  2. Create two methods named “verifyString” and “verifyVariableValue”.
  3. Add annotation as “@Test” both the methods.
  4. Run as a TestNG suite.

Java Program:

You need to run it as a TestNG test. Right click on Class Name in project hierarchy or right click on opened windows of program and select Run As-> TestNg test.


After running tests, you will can see output in two tabs: Console and Result of running class <Class Name>. It will show you how many tests are passed , failed and skipped. We will see these result tab in details in later posts. You can see single failure as your first test must be fail as “Selenium Webdriver” and “Selenium” both are not equal.

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

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 5: How To Create And Run A TestNG Class

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