How to run TestNG from IntelliJ IDEA?


TestNG allows to run the test suites from IntelliJ IDE as well as command line.

Usually, IntelliJ IDE is handy to run testng.xml for development purpose while command line (cmd) for actual execution.

There are few pre−requisites to run test suites from IntelliJ IDE:

  • testng.xml file should be created to define test suites and testing classes to execute.

  • All dependent jars should be configured as External Libraries. It includes testing.jar, jcommander.jar and any other jars those are used in test cases. It usually gets done while setting up the project first time.

  • JDK set up at project level, it can be verified inside External Libraries.

The following screenshot shows where to check for pre-requisite:

Approach/Algorithm to solve this problem

  • Step 1: Confirm all pre−requisites are available.

  • Step 2: Go to the top right side of the IDE and click on Add Configuration as shown in below screenshot:

  • Step 3: It opens the Run/Debug Configurations pop−up.

  • Step 4: Click on + icon present at top left side as shown below

  • Step 5: Choose TestNG from available selections as shown in below screenshot.

  • Step 6: Now, following information should be provided in respective place as explained below:

Name: Provide user defined name to identify the configuration. For ex: testng−xml

Configuration −> Test Kind: Select Suite. However, it supports at class, methods, group, pattern as well.

Suite: Provide the path where testng.xml file is created. User can browse as well by clicking at folder sign present at right corner.

Select In whole project radio button out of three.

Output directory: User can provide a path where result should get created. If it is blank result files will be created at Project−>test−output

JDK Settings: VM Options and Working directory will be populated by default. Make sure the correct JRE is selected to execute the testng.xml.

  • Step 7: If Output directory is not provided, go to Listeners and check the checkbox for use default reporter as shown in below screenshot:

  • Step 8: Now Click on Apply and then OK present at bottom right side as shown in below screenshot:

  • Step 9: Now user can see the name of configuration as testng-xml instead of Add Configuration.

  • Step 10: To run the testng−xml, click on > right arrow sign or Shift+F10 present beside the Configuration while click on another symbol just beside right arrow sign for debug or press Shift+F9 as shown in below screenshot.

Updated on: 17-Aug-2023

895 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements