Java 在testng报告中跳过测试方法结果
我有一个关于testng的问题 我有点像:Java 在testng报告中跳过测试方法结果,java,testng,Java,Testng,我有一个关于testng的问题 我有点像: @Test public initializeMethod() { //here I do something that is needed before my real test method } @Test (depends on initializeMethod) public myRealTest1{ //my test 1 } @Test (depends on myRealTest1) public myRealTest2{ //m
@Test
public initializeMethod() {
//here I do something that is needed before my real test method
}
@Test (depends on initializeMethod)
public myRealTest1{
//my test 1
}
@Test (depends on myRealTest1)
public myRealTest2{
//my test 2
}
是否可以跳过testng报告中的initializeMethod(我的意思是在报告中我希望看到测试的实际计数(2而不是3))?
@Test
注释专门用于测试。您必须使用非测试对方法initializeMethod()
进行正确的注释。有几种选择:
@BeforeTest
@BeforeClass
其他可能的注释:
@BeforeSuite
@BeforeGroups
@BeforeMethod // if you want `initializeMethod()` run before every test.
如果要在每个实际测试方法之前运行initializeMethod(),可以使用@BeforeMethod注释。 @BeforeMethod:带注释的方法将在每个测试方法之前运行。 因此,您需要按如下方式声明该方法:
@BeforeMethod
public initializeMethod() {
//here I do something that is needed before my real test method
}
@BeforeClass
public initializeMethod() {
//here I do something that is needed before my real test method
}
如果只想运行initializeMethod()一次,可以使用@BeforeClass注释。 @BeforeClass:在调用当前类中的第一个测试方法之前,将运行带注释的方法。 因此,您需要按如下方式声明该方法:
@BeforeMethod
public initializeMethod() {
//here I do something that is needed before my real test method
}
@BeforeClass
public initializeMethod() {
//here I do something that is needed before my real test method
}