Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在testng报告中跳过测试方法结果_Java_Testng - Fatal编程技术网

Java 在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

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

@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
}