我这个怎么只是执行一次呢?
来源:5-4 注解实战BeforeMethod和AfterMethod

热爱编程学习
2022-05-08
package com.course.testng;
import org.junit.jupiter.api.Test;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class BasicAnnotation {
@Test
public void testCase1(){
System.out.println("test");
}
@BeforeMethod
public void beforeMethod(){
System.out.println("testone");
}
@AfterMethod
public void afterMethod(){
System.out.println("testtwo");
}
}
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<groupId>com.coutest.code</groupId>
<artifactId>Chapte</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
写回答
1回答
-
@BeforeMethod 和 @AfterMethod 是在方法前和方法后执行,你的这个类中只包含一个方法testCase1(),所以就只执行一次了
012022-05-11
相似问题