Jason Gowan

TestNG - Hello World

An example to get started with TestNG and maven.

Maven

Add the following to the maven dependencies.

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8.8</version>
  <scope>test</scope>
</dependency>

Create a Test

Next create a class in src/test/java called ExampleTest.

import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class ExampleTest {
    
    @Test
    public void exampleTest(){
        assertEquals(2 + 2, 4, "2 + 2 should equal 4");
    }

}

Run the Test

Execute mvn test in the maven project to run the test.

The code for this example can be found on github.