zoukankan      html  css  js  c++  java
  • java8+junit5实现并发测试(多线程)

    1.配置线程

    #是否允许并行执行true/false
    junit.jupiter.execution.parallel.enabled = true
    #是否支持方法级别多线程same_thread/concurrent
    junit.jupiter.execution.parallel.mode.default = concurrent
    #是否支持类级别多线程same_thread/concurrent
    junit.jupiter.execution.parallel.mode.classes.default = concurrent
    # the maximum pool size can be configured using a ParallelExecutionConfigurationStrategy
    junit.jupiter.execution.parallel.config.strategy=fixed
    junit.jupiter.execution.parallel.config.fixed.parallelism=10

    2. 编写并发测试的代码

    import com.wechat.apiobject.DepartMentObject;
    import com.wechat.apiobject.TokenHelper;
    import io.restassured.response.Response;
    import org.junit.jupiter.api.*;
    import org.junit.jupiter.api.parallel.Execution;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import static org.junit.jupiter.api.Assertions.assertEquals;
    import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT;
    
    /**
     * 对创建部门进行并发测试
     */
    @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
    public class Demo_06_1_thread_creatdepartment {
        private static final Logger logger = LoggerFactory.getLogger(Demo_06_1_thread_creatdepartment.class);
        static String accessToken;
    
        @BeforeAll
        public static void getAccessToken() throws Exception {
            accessToken = TokenHelper.getAccessToken();
            logger.info(accessToken);
    
        }
    
        @DisplayName("创建部门")
        @RepeatedTest(100)
        @Execution(CONCURRENT)
        void createDepartment() {
            String creatName= "name1234567";
            String creatEnName="en_name1234567";
    
            Response creatResponse = DepartMentObject.creatDepartMent(creatName,creatEnName,accessToken);
            assertEquals("0",creatResponse.path("errcode").toString());
        }
    }
  • 相关阅读:
    Python全栈-第四课 学习笔记
    Python全栈-第三课 学习笔记
    Python全栈-第二课 学习笔记
    计算机网络技术-交换基础和Vlan间路由 学习笔记
    Linux运维-04系统管理和操作命令
    Linux运维-03远程连接
    Linux运维-02操作系统和系统安装(虚拟机)
    Linux运维-01硬件组成概念介绍
    计算机网络技术-路由-OSPF 学习笔记
    python基础 day17 模拟博客园登录
  • 原文地址:https://www.cnblogs.com/cythia2018/p/14660025.html
Copyright © 2011-2022 走看看