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:
- Are String “Selenium WebDriver” and “Selenium” equal?
- 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:
- Create a plain java class.
- Create two methods named “verifyString” and “verifyVariableValue”.
- Add annotation as “@Test” both the methods.
- Run as a TestNG suite.
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.
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