junit5 入门系列教程-30-junit5 实战例子 junit performance

目录

实战项目

本系列的学习也正是为了将原来的项目,从 junit4 升级到 junit5

junitperf

Java 性能测试框架工具-JunitPerf

junit5 的新特性

注解定义

ps: 为了简化说明,删除了其他的属性。

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.commons.annotation.Testable;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Set;

/**
 * 执行接口
 * 对于每一个测试方法的条件配置
 * @author bbhou
 * @version 1.0.0
 * @since 1.0.0
 */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
@Documented
@ExtendWith(PerfConfigProvider.class)
@TestTemplate
public @interface JunitPerfConfig {
    /**
     * 执行时间。(单位:毫秒)
     * 默认值:默认为 1min
     * 这里的执行时间不包含准备时间。
     * @return time in mills
     */
    long duration() default 60_000L;
}

使用

这样,就可以直接执行该测试方法。不再需要其他额外的注解。
将执行 @ExtendWith(PerfConfigProvider.class)中对应的实现。

import com.github.houbb.junitperf.core.annotation.JunitPerfConfig;

public class HelloWorldTest {

    @JunitPerfConfig(duration = 1000)
    public void helloTest() throws InterruptedException {
        Thread.sleep(100);
        System.out.println("Hello Junit5");
    }

}

代码地址

有兴趣的参见 junitperf

系列导航

系列导航

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值