TestNG : Basic Annotations used in testNG


This blog introduces the basic annotation supported in TestNG.

import java.util.*;
import org.testng.Assert;
import org.testng.annotations.*;

public class TestNGTest1 {

    private Collection collection;

    public void oneTimeSetUp() {
        // one-time initialization code   
    	System.out.println("@BeforeClass - oneTimeSetUp");

    public void oneTimeTearDown() {
        // one-time cleanup code
    	System.out.println("@AfterClass - oneTimeTearDown");

    public void setUp() {
        collection = new ArrayList();
        System.out.println("@BeforeMethod - setUp");

    public void tearDown() {
        System.out.println("@AfterMethod - tearDown");

    public void testEmptyCollection() {
        System.out.println("@Test - testEmptyCollection");

    public void testOneItemCollection() {
        System.out.println("@Test - testOneItemCollection");


@BeforeClass - oneTimeSetUp
@BeforeMethod - setUp
@Test - testEmptyCollection
@AfterMethod - tearDown
@BeforeMethod - setUp
@Test - testOneItemCollection
@AfterMethod - tearDown
@AfterClass - oneTimeTearDown
PASSED: testEmptyCollection
PASSED: testOneItemCollection


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.