TestNG

Hirudini Udugama
3 min readNov 5, 2020

--

Today we are going to learn on TestNG in test automation.

TestNG is a testing framework for the Java and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities. It pioneered the annotations-based approach to Java testing that was later adopted for JUnit 4.

Here we are going to discuss how TestNG can be applied in unit testing.

TestNG environment setup

We can use code editor like intelliJ idea, eclipse or any other similar one. Here I’m going to use intelliJ idea for demonstration.

Let’s create a new project. In intelliJ idea we can simply create maven project as follows.

File → New → Project → Maven

(Maven should be downloaded before)

Now you can simply give a project name and location.

Now you have your maven project.

Here we can see that two separate folders as main and test for development and testing purposes.

In pom.xml file we add external libraries that we want. We use <dependencies> tags to add those dependencies. And also we use <build> tags to mention what are the technologies that we are going to use and so on. Let’s add dependencies first.

Add TestNG dependency

Search maven repository → https://mvnrepository.com/

Search there for TestNG

Now we can see the versions of TestNG and here at the moment 7.3.0 is the latest stable version that they have released. Just click on it.

Highlighted part is the TestNG dependency that we are going to add. Just copy it and paste it in pom.xml file as follows.

Multiple dependencies can be added under the same dependencies tags. Now TestNG environment setup is done.

Hope you understood what is TestNG, how to set up TestNG environment and adding TestNG dependency. See you in another lesson. Happy learning!!!

Hirudini Udugama

--

--

Hirudini Udugama
Hirudini Udugama

Written by Hirudini Udugama

Undergraduate at University of Moratuwa

No responses yet