pom.xml加入
9 P: Z: a" s& J2 P- k0 u
0 C; Y+ G9 U5 Z; N! K# A3 j( Q3 b<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 > / v, ]% z- X/ ?/ W4 n& ^- F7 g
@Test" i& a; l( x' o7 z3 }
public void MultiRequestsTest() {
* [! `/ T1 t" I7 H6 w" k // 构造一个Runner
' n3 w6 D2 w& ~5 z' ~/ M' ~ TestRunnable runner = new TestRunnable() {& L, x" `; @8 E `! X
@Override. E* ` e9 l' O8 t/ T! w8 n
public void runTest() throws Throwable {" |: @& T" M" T6 `2 a* F5 T0 h1 j0 s
// 测试内容 U/ t* K% w* V! P# B
. E9 v z' E/ |0 Q
5 P5 i% { R8 r( n- c! e }/ L3 n5 o, o; E- E& ~3 H; n# F- r8 E
};
) W# E* t9 Y" X/ v/ T3 E. @' U int runnerCount = 1000;2 k0 K% n7 H. D
// Rnner数组,想当于并发多少个。5 v7 V4 M1 [$ z* ~; T; M
TestRunnable[] trs = new TestRunnable; f+ N1 x" [$ G+ B+ R( Y0 B
) X3 B9 A$ ?# l+ z. O- f[runnerCount];8 ~8 {3 ]( M7 m$ T8 t: z
for (int i = 0; i < runnerCount; i++) {
6 H% d7 ?- w0 S* F; y trs = runner;0 T! x" R$ B; p; ^0 a% s
}
2 \5 Z8 G% a& z // 用于执行多线程测试用例的Runner,将前面定义的
+ L# \2 k) y1 e0 E; M3 D$ z" _0 A4 O, C3 K9 j/ d1 K
单个Runner组成的数组传入
2 a+ t6 I3 u4 d. b3 r: j8 p MultiThreadedTestRunner mttr = new
5 N+ j z# q0 T5 k" ?; _& S
. [* P8 C4 M1 V+ |0 }1 LMultiThreadedTestRunner(trs);
$ j: C: o; f# v try {" ^$ J l& R* q! \7 z4 \7 J
// 开发并发执行数组里定义的内容1 l w# r2 h1 H& n5 O2 t7 Y% T
mttr.runTestRunnables();
% k' A) k# ^- S( Y } catch (Throwable e) {- ^2 ~1 v/ Q0 m8 @* _* U8 p
e.printStackTrace();
3 F* U( M7 b) b" |6 l. G }! k0 c, z6 {1 E; y! O- ^5 o# K4 O
}/ b. A+ B3 L, ^" n
^9 E, d- x: X8 Y
groboutils-core-5.jar百度网盘下载地址:java自学网(javazx.com)groboutils-core-5.jar.zip【密码回帖可见】1 J! m6 Y I/ k( U- L
9 N' i2 ^' T) k7 q
; ~; n" Q) P/ Z- v; K( a
- h& p. l9 {% S
- N; p8 N+ m5 f9 o& a+ h |