2012-08-02 82 views
1

我有一个关于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 
} 

是否有可能跳过initializeMethod在TestNG的报告(我的意思是,在报告中,我希望看到的测试(2而不是3个实数数))?

回答

1

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

@BeforeTest 
@BeforeClass 

其他可能的注解:

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

如果你想每一个真实的测试方法之前运行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 
}