pom.xml加入
; m8 ]% g9 g5 S7 j! }% \$ e2 o0 h# g4 x/ P( ~. y9 F( k
<dependency> <groupId >net.sourceforge.groboutils </groupId > <artifactId >groboutils-core</ artifactId> <version >5 </version > <scope >system </scope > <!--本地jar的路径,相对或者绝对都可以 --> <systemPath >D:\ groboutils-core-5.jar</systemPath > </dependency > " t9 O- z1 p* x
@Test: R! p1 D( R0 O/ L$ K3 R) L/ H
public void MultiRequestsTest() {
3 ~5 u+ A$ {, H5 S' M0 P( K9 s4 L // 构造一个Runner
2 d5 R3 y7 }4 X) H% F TestRunnable runner = new TestRunnable() {
% V; l( Q" t/ E4 L F @Override( I6 F! l% N6 u, R
public void runTest() throws Throwable {, \2 I1 x0 j( e4 `; c' M% {3 D# t
// 测试内容+ j7 l; ~+ R3 z% a& Y( ~
; _- h, l$ V. u6 _6 C: P 3 l' n5 I) G- E0 C
}
{/ m: D0 ]- d7 T };( T* w" W/ x4 j/ L$ s5 H& g
int runnerCount = 1000;3 A# ?% {" g" u2 W
// Rnner数组,想当于并发多少个。
; b) O) j% k5 O8 W* c' W4 q TestRunnable[] trs = new TestRunnable
3 R A3 x V9 u- x5 `" G4 }; L; o# L7 ^. H/ P. x
[runnerCount];5 N/ _) T1 d9 I& p/ f
for (int i = 0; i < runnerCount; i++) {; E1 I: g1 i1 r& H5 ^+ W
trs = runner;% G0 G3 Z2 K* H q7 }
}
1 r8 ^ W5 X) E" A // 用于执行多线程测试用例的Runner,将前面定义的
+ S2 |! j# ^. V" G. u- A4 N/ y, w" R* F
单个Runner组成的数组传入
( B- X& X3 S5 t* I" w* z- { MultiThreadedTestRunner mttr = new
6 |( L5 S) w/ b8 r7 O/ a0 k# G6 a) u) \; h5 K
MultiThreadedTestRunner(trs);, u% s, D6 y- _ Y# }# T
try {( o) l# Z M* o( W3 m# M
// 开发并发执行数组里定义的内容5 F- `$ e. D: X: z; C, X
mttr.runTestRunnables();' A5 ~' ?. W8 W0 C; \$ n8 l5 j# b
} catch (Throwable e) {& E# U. h( u8 K( a* P
e.printStackTrace();. g% _9 W7 [6 Z' |
}
1 o( j4 K6 d9 V8 d2 O4 y7 A }
9 y% `, g0 K9 a' B" O! \
( `. \4 G' L% y5 {' jgroboutils-core-5.jar百度网盘下载地址:java自学网(javazx.com)groboutils-core-5.jar.zip【密码回帖可见】
/ V/ b2 D; q5 @7 n) m5 L8 k- P% _ o! h' m
v! i4 z5 l) W6 T, } b1 t7 h0 L/ d0 J
, H& l% A$ M2 X7 \% a2 s |