2012年1月17日星期二

多线程测试

JUNIT 不支持多线程
http://groboutils.sourceforge.net/

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
import net.sourceforge.groboutils.junit.v1.TestRunnable;


import org.junit.Test; 

class TestRunnableImpl extends TestRunnable{ 
@Override
public void runTest() throws Throwable {
//do something
}

}
public class MutilThreadTest { 
@Test
public void transaction() throws Throwable{ 
  List<TestRunnable> list = new ArrayList<TestRunnable>();
for (int i = 0; i < 50; i++) {
list.add(new TestRunnableImpl(ctx));
}
TestRunnable[] empty = new TestRunnable[0];
MultiThreadedTestRunner mttr = new MultiThreadedTestRunner( list.toArray(empty) );
                mttr.runTestRunnables( 2 * 60 * 1000 );

}

没有评论:

发表评论