Back to Course
TestNG & Maven

TestNG Annotations Usage

Example

public class LoginTest {
    @BeforeClass
    public void setup() {
        // runs once before all tests in this class
    }

    @Test
    public void validLoginSucceeds() {
        // test logic
    }

    @AfterClass
    public void teardown() {
        // runs once after all tests in this class
    }
}

Execution Order

TestNG guarantees a predictable order: Before-Suite → Before-Class → Before-Method → Test → After-Method → After-Class → After-Suite, ensuring setup/cleanup always wraps the actual test correctly.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course