本文介绍了TestNG中BeforeTest和BeforeMethod有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
两个注解都在 testNG 中的 @test 之前运行,那么它们之间的区别是什么.
Both annotations runs before the @test in testNG then what is the difference between two of them.
推荐答案
检查下面的代码和输出
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Test_BeforeTestAndBeforeMethod {
@BeforeTest
public void beforeTest()
{
System.out.println("beforeTest");
}
@BeforeMethod
public void beforeMethod()
{
System.out.println("\nbeforeMethod");
}
@Test
public void firstTest()
{
System.out.println("firstTest");
}
@Test
public void secondTest()
{
System.out.println("secondTest");
}
@Test
public void thirdTest()
{
System.out.println("thirdTest");
}
}
输出:
beforeTest
beforeMethod
firstTest
beforeMethod
secondTest
beforeMethod
thirdTest
这篇关于TestNG中BeforeTest和BeforeMethod有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!