• Junit借助Groboutils Core进行并发测试


    本文参考:http://www.voidcn.com/article/p-ybnvuffh-ke.html;转载请注明出处

    junit是无法进行并发测试,但是又有需要并发测试的场景怎么办呢?此时可以借助一个插件(Groboutils Core)来完成这种功能。

    maven仓库地址:https://mvnrepository.com/artifact/net.sourceforge.groboutils/groboutils-core

    第一步:在项目的pom.xml中加入依赖:

    <!-- https://mvnrepository.com/artifact/net.sourceforge.groboutils/groboutils-core -->
    <dependency>
      <groupId>net.sourceforge.groboutils</groupId>
      <artifactId>groboutils-core</artifactId>
      <version>5</version>
      <scope>test</scope>
    </dependency>
    View Code

    第二步:在单测中进行代码编写

     @Test
      public void testConcurrentInitOrBind() {
    
        // mock一个返回
        doReturn(Lists.newArrayList(userMemberCard)).when(operateCardDao)
            .queryCardByRegisterMobileAndTenantId(anyString(), anyLong());
    
        TestRunnable runner = new TestRunnable() {
          // 在runTest方法中填写自己的测试方法
          @Override
          public void runTest() throws Throwable {
            InitCardResVo resVoFirst = operateCardService.initOrBindCard(requestVo);
            System.out.println("result resVoFirst is:" + resVoFirst.toString());
          }
        };
    
        // 一个数组,代表并发个数。此处并发5个
        TestRunnable[] trs = new TestRunnable[5];
        for (int i = 0; i < 5; i++) {
          trs[i] = runner;
        }
        MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(trs);
        try {
          mttr.runTestRunnables();
        } catch (Throwable ex) {
          ex.printStackTrace();
        }
      }
    View Code
  • 相关阅读:
    VMware6.0-vCenter的安装准备及安装
    VeeamBackup9.5安装与配置
    VeeamOne(Free Edition 9.5 )-安装与配置
    UIDatePicker
    UIImagePicker照片选择器
    UIImageView
    UILabel
    UIScrollView 期本使用方法
    UISegment
    UISlide
  • 原文地址:https://www.cnblogs.com/lvmengtian/p/10516942.html
Copyright © 2020-2023  润新知