1. What is TestNG?
TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as:
Annotations.
Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc...).
Test that your code is multithread safe.
Flexible test configuration.
Support for data-driven testing (with @DataProvider).
Support for parameters.
Powerful execution model (no more TestSuite).
Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc).
Embeds BeanShell for further flexibility.
Default JDK functions for runtime and logging (no dependencies).
Dependent methods for application server testing.
and that is the official description of TestNG, source https://testng.org/doc/
2. Requirements
TestNG supports JDK 7 or higher. Once you have the required Java installed onto your system, download TestNG jar from the link https://mvnrepository.com/artifact/org.testng/testng/6.7
3. Importing TestNG to Intellij
Open your Intellij and go to File --> Project Structure or Ctrl+Alt+Shift+S. Choose Modules from Project Settings, in Dependency table import your TestNG Jar then select and apply to your current project.
4. Writing and Executing Test Code
CODE
import org.testng.annotations.Test;
public class Sample {
@Test()
void Testone(){
System.out.println("This is Test 1");
}
}
EXPLANATION
Test in the TestNG are mentioned with annotation followed my keyword Test. As you can see the Class file doesn't need a main method. Run the above code then you will see similar output on your IDE
In the output you can see the total no of Test Cases with no of test passed and failed.