springboot项目中进行并发测试
时间:2019-05-08 22:14:15
收藏:0
阅读:740
一 利用工具包:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.databene</groupId> <artifactId>contiperf</artifactId> <version>2.3.4</version> <scope>test</scope> </dependency>
引入者两个依赖:
就可以进行测试了,看测试代码:
package com.cxy.springs; import com.cxy.springs.entity.TUser; import com.cxy.springs.service.TUserService; import org.databene.contiperf.PerfTest; import org.databene.contiperf.junit.ContiPerfRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest public class SpringsApplicationTests { @Autowired public TUserService userService; @Test public void contextLoads() { } //引入 ContiPerf 进行性能测试 @Rule public ContiPerfRule contiPerfRule = new ContiPerfRule(); @Test //10个线程 执行10次 @PerfTest(invocations = 100,threads = 10) public void test() { TUser load = userService.load(1); System.out.println(load.getPhone()); } }
结果:
不知道为什么我的图片挂了
第二种方式:
利用concurrent包下列进行测试,不过他们没有具体的相应时间:
原文:https://www.cnblogs.com/xiufengchen/p/10835040.html
评论(0)