我这个怎么只是执行一次呢?

来源: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回答

大周

2022-05-11

@BeforeMethod 和 @AfterMethod 是在方法前和方法后执行,你的这个类中只包含一个方法testCase1(),所以就只执行一次了

0
1
热爱编程学习
非常感谢!
2022-05-11
共1条回复

Java接口自动化测试实战,搞定理论基础+典型应用场景

打破传统测试用例设计方法,搞懂基于TestNG的接口自动化测试技术

2086 学习 · 920 问题

查看课程