跳过测试方法导致testng报告

时间:2012-08-02 13:19:26

标签: 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{
//my test 2
}

是否可以在testng报告中跳过initializeMethod(我的意思是在报告中我想看到真正的测试次数(2但不是3))?

2 个答案:

答案 0 :(得分:1)

@Test注释专门用于测试。您必须使用非测试annotation正确注释方法initializeMethod()。有几种选择:

@BeforeTest
@BeforeClass

其他可能的注释:

@BeforeSuite
@BeforeGroups
@BeforeMethod // if you want `initializeMethod()` run before every test.

答案 1 :(得分:1)

如果要在每个真正的Test方法之前运行initializeMethod(),可以使用@BeforeMethod注释。 @BeforeMethod:带注释的方法将在每个测试方法之前运行。 所以,你需要声明如下方法:

@BeforeMethod
public initializeMethod() {
//here I do something that is needed before my real test method
}

如果只想运行一次initializeMethod(),可以使用@BeforeClass注释。 @BeforeClass:在调用当前类中的第一个测试方法之前,将运行带注释的方法。 所以,你需要声明如下方法:

@BeforeClass
public initializeMethod() {
//here I do something that is needed before my real test method
}