TestNG is a testing framework inspired by JUnit and NUnit with added new functionality that makes it more powerful and easy to use. TestNG can be used for unit testing, integration, end-to-end and functional testing.
Features of TestNG:
- Flexible test configuration
- Powerful execution model
- Supported by various tools and plugins (Eclipse, IDEA, Maven, etc.)
- Support of parameters
- Supports various kinds of annotations.
- Download Eclipse IDE
- Create a maven project in Eclipse
- Add various dependencies like selenium, TestNg, WebDriver Manager
- Download and install TestNG from the eclipse marketplace
In the first step, we would be creating a maven project inside the eclipse. We would fill in basic details like name, group id, description, etc.
In Second step we would be adding a package and then create an execution file.
After creating the project setup, we will navigate to mvn repository and search for various kinds of dependencies that we will be using in our project as shown below.
We can notice a small code snippet in the above figure, this is nothing but the dependency code which we need to copy and paste into the pom.xml file.
Likewise, we have to download mainly 3 dependencies from mvn repository.
- Selenium java
- Web Driver manager
After downloading all required dependencies, our pom.xml file would look like the below.
After all configuration, we will find a folder structure in the pattern as shown above. It would consist of various folders; our main test file would be located under the com.practice.test package.
To understand how TestNG works we would create a simple test that will launch the browser and search a basic query as shown below.
- In the above code, we have created a method (TestGoogle) inside the class.
- Above which it has annotations @Test, this signifies that this test case is based on TestNG.
- Right after the method, we would be adding a setup that consists of a chrome driver.
- After all this, we would further go ahead with launching the browser (Google.com) and thus search for ‘neova solutions’ and click enter.
- Lastly, we would get a title after the search query is executed.
Note: Using the same technique, we can also launch various other browsers like Firefox or internet explorer as shown below.
After the Execution of the code, we will see the results below, which signify that our Test has passed.
In this blog, we have covered a comprehensive introduction to TestNG, various features and advantages of TestNG, and provided a step-by-step guide for setting up a TestNG project in Eclipse IDE. It also includes a basic test case that demonstrates the capabilities of TestNG, along with the test results and generated report.