IntelliJ IDEA 2021.2 Help

TestNG

To create a TestNG test class, you can use the Create Test intention action.

You can also create a new class for your TestNG test and then add the necessary code to that class. This way of creating a TestNG class is described on this page.

Creating a TestNG test class

  1. In the Project tool window, right click the directory where you want to create a new test class.

  2. Select New | Java Class from the context menu.

  3. In the Create New Class dialog, specify the class name and click OK.

  4. In the editor, write the code for your test class. Use the TestNG annotations where necessary. For example, you may want to annotate the whole class or individual methods:

    @Test() public class testetsng { @DataProvider public Object[][] data() { return new String[][] {new String[] {"data1"}, new String[] {"data2"}}; } @Test(dataProvider = "data") public void test(String d) { Assert.assertEquals("First Line>\nSecond Line", "Third Line\nFourth Line"); } }

    If the annotation you add lacks the import statement, the corresponding intention action will suggest you to create one.

YAML in TestNG

TestNG supports defining a test suite using YAML, however it doesn't contain the YAML parser by default. If you want to use a YAML file, add the snakeyaml dependency. The version should correspond with the TestNG version that you use.

For example, if your project uses Maven, add the org.yaml.snakeyaml dependiency to your pom.xml.

Last modified: 02 August 2022