首页 > 其他分享 >SSH框架学习(十、Junit+GroboUtils进行多线程测试)

SSH框架学习(十、Junit+GroboUtils进行多线程测试)

时间:2023-01-04 13:36:28浏览次数:62  
标签:TestRunnable GroboUtils springframework SSH org import 多线程 new junit


Junit4不能模拟多线程的情况,需要其他支持,我用的是GroboUtils,最新版本5,下载地址:​​http://groboutils.sourceforge.net/downloads.html​


GroboUtils测试的代码是用网上抄来的,来源:​​http://www.coderli.com/multi-thread-junit-grobountils​

UserDAOImplTest的代码

package demo.myssh.dao.impl;

import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
import net.sourceforge.groboutils.junit.v1.TestRunnable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.*;
import demo.myssh.dao.IUserDAO;
import demo.myssh.model.User;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "file:WebRoot/WEB-INF/applicationContext.xml" })
public class UserDAOImplTest {

@Autowired
@Qualifier("iUserDAO")
private IUserDAO userDao;

@Test
@Repeat(2)
public void MultiRequestsTest() {
// 构造一个Runner
TestRunnable runner = new TestRunnable() {
@Override
public void runTest() throws Throwable {
// 测试内容
// System.out.println("a");
userDao.save(new User("aa", "bb", "cc"));
}
};
int runnerCount = 2;
// Rnner数组,相当于并发多少个。
TestRunnable[] trs = new TestRunnable[runnerCount];
for (int i = 0; i < runnerCount; i++) {
trs[i] = runner;
}
// 用于执行多线程测试用例的Runner,将前面定义的单个Runner组成的数组传入
MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(trs);
try {
// 开发并发执行数组里定义的内容
mttr.runTestRunnables();
} catch (Throwable e) {
e.printStackTrace();
}
}
}



标签:TestRunnable,GroboUtils,springframework,SSH,org,import,多线程,new,junit
From: https://blog.51cto.com/u_15929643/5988310

相关文章

  • ssh登录及su切换用户慢
    参考:https://www.cnblogs.com/yunqingtuo/p/13412491.htmlsystem-logind排查方法1、通过trace-tsuroot可以发送耗时在什么地方,但是也获取不到有用的信息2、通过......
  • Linux系统 免密ssh登录配置及解释说明
    一、在需要登录的源机器上生成密钥(比如从A登录到B和C,就需要在A源机器上生成密钥,然后把公钥文件内容,复制到B和C目标机器上)(这就好比公司的指纹锁,你需要把你的指纹录入进去,......
  • 在linux上Git配置多个SSH-Key
    Git配置多个SSH-KeySSHKey背景当有多个git账号时,比如:a.一个gitee,用于公司内部的工作开发;b.一个github,用于自己进行一些开发活动;c.一个gitlab,用于自己进行一些开发......
  • ubuntu22.04启用sshd远程
    1.系统升级ubuntu有一个很麻烦的特性,就是新装的系统需要先更新系统:sudoapt-getupdate-y2.安装openssh-server【sshd】sudoaptinstall openssh-server 3.开......
  • Linux远程命令+传输文件+清除ssh public key
    #!/bin/bashif[["$1"=='']];thenecho"iperror!*.sh192.168.1.1"exit0fiecho$1chmod+x/usr/local/test/agent>/root/.ssh/known_hostssshpas......
  • Linux基础:ssh与scp
    登陆登陆服务器sshuser@hostnameuser:用户名hostname:IP地址或域名第一次登陆会提示Theauthenticityofhost'123.57.47.211(123.57.47.211)'can......
  • Linux网络第四章:SSH远程管理及通过SSH实现服务器之间的免密连接
    目录一、SSH远程管理基础1、ssh协议2、ssh原理3、配置文件解析4、登录方法5、使用ssh协议传输的命令二、免密连接的实现1、免密连接原理 2、免密实现环境准备3......
  • TCP IP网络编程(13) Linux下epoll与多线程
    优于select的epoll1.epoll的理解与应用  select服用方法由来已久,在《TCP/IP网络编程(6)》中,介绍了如何使用select方法实现IO复用。但是利用该技术后,无论如何优化程......
  • 在多线程创建TFPHTTPClient对象并发送请求时出现Could not initialize OpenSSL librar
    在多线程创建TFPHTTPClient对象并发送请求时出现CouldnotinitializeOpenSSLlibrary应该怎么解决?单线程的时候没有遇到。经网友指导下使用以下方法就可以解决这个问题:......
  • 【Python】爬虫笔记-多线程&线程池
    1.基本概念1.1并发和并行并发和并行的概念并不是对立的,并发(concurrent)对应的是顺序(sequential),并行(parallel)对应的是串行(serial)。顺序:上一个开始执行的任务完成后,当前......