TestingBeforeMethods.java
package com.javaskool;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class TestingBeforeMethods {
@BeforeClass // run before start of first test
public void beforeClass()
{
System.out.println("Running BeforeClass test");
}
@AfterClass // run after end of all test
public void afterClass()
{
System.out.println("Running afterClass test");
}
@BeforeTest // run before start of any test
public void before()
{
System.out.println("Running Before test");
}
@AfterTest // run after end of all test
public void after()
{
System.out.println("Running after test");
}
@BeforeMethod // run before start of every method
public void beforeMeth()
{
System.out.println("Running Before method");
}
@AfterMethod // run after end of every method
public void afterMeth()
{
System.out.println("Running after method");
}
@Test
public void testmethod1()
{
System.out.println("Test Method1");
}
@Test
public void testmethod2()
{
System.out.println("Test Method2");
}
}
Output
Running Before test
Running BeforeClass test
Running Before method
Test Method1
Running after method
Running Before method
Test Method2
Running after method
Running afterClass test
Running after test
PASSED: testmethod1
PASSED: testmethod2
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
Click here to download example with jar files.[4.5 MB]
Recent Comments