jack-zheng
9/19/2018 - 6:55 AM

testng, java, order

testng, java, order

Executor Order Of TestNG

package testngsample;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AnnotationTestTest {
    @BeforeTest
    public void before_test(){
        System.out.println("Call From Before Test");
    }

    @BeforeMethod
    public void before_method(){
        System.out.println("Call From Before Method");
    }

    @Test
    public void test01(){
        System.out.println("Call From Test 01");
    }

    @Test
    public void test02(){
        System.out.println("Call From Test 02");
    }

    @AfterMethod
    public void after_method(){
        System.out.println("Call From After Method");
    }

    @AfterTest
    public void after_test(){
        System.out.println("Call From After test");
    }
}

Console Output

  • before test will only execute once for every suit
  • before method will execute for every test case
[TestNG] Running:
  /Users/User/Library/Caches/IdeaIC2018.1/temp-testng-customsuite.xml
Call From Before Test
Call From Before Method
Call From Test 01
Call From After Method
Call From Before Method
Call From Test 02
Call From After Method
Call From After test

===============================================
Default Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================


Process finished with exit code 0