First Test case Using TestNg: In this post, we are trying to learn how we can create our first test case by using TestNG. Before going through the application, verify that on your local machine, TestNG is installed or not.
If TestNG is not installed, then we have written a detailed article about that and by following that you can install TestNG on your local machine on your own without taking others’ help.
First Test case with TestNG Guide
If TestNG is already installed on your local machine, then follow the below steps to create TestNG class:
- You can directly create a testNG class by pressing the CTRL + N and Select “TestNG Class” at the TestNG category and Click Next [OR] You can do the same by right click on the project – Select TestNg and after that, choose to Create TestNG class.
- If you have already set up your project and when you are creating the test cases, then by default by default few things are auto pre polluted like source folder location and package name on the form. Enter a class name in the class name text box, and under that, you will get the different annotations, and there you need to select “@BeforeMethod,” “@AfterMethod,” and click Finish.
- After Click on the finish, it will display a newly created testNG class under that package. In that class, you can see three empty methods with three different annotations like @Test, @BeforeMethod & @AfterMethod.
- Let us Use those three methods and write the script for different purposes like
@BeforeMethod: Launch Firefox and Direct to the SoftwareTestingo
@Test: Get The Page Title
@AfterMethod: Close The Browser