标签:
package com.xiw.core;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* 单元测试基类
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:beans.xml"})
public abstract class BaseServiceTest extends AbstractTransactionalJUnit4SpringContextTests {
}
package com.xiw.core;
import java.util.HashMap;
import java.util.Map;
import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
import net.sourceforge.groboutils.junit.v1.TestRunnable;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import com. xiw.user.autobid.AutoBidService;
import com. xiw.user.business.IRechargeBiz;
import com. xiw.user.dao.IRechargeDao;
import com. xiw.util.Constant;
import com. xiw.util.LogUtilForLog4j;
public class ServiceTest extends BaseServiceTest {
@Autowired
private IRechargeBiz revharegBiz;
@Test
@Rollback(value = false)
public void thread1(){
// 构造一个Runner
TestRunnable runner = new TestRunnable() {
@Override
public void runTest() throws Throwable {
// 测试内容
revharegBiz.update1();
}
};
int runnerCount = 3;
//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();
}
}
}
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.groboutils</groupId>
<artifactId>groboutils-core</artifactId>
<version>5</version>
</dependency>
Repository | Opensymphony Releases |
Repository url | https://oss.sonatype.org/content/repositories/opensymphony-releases |
标签:
原文地址:http://www.cnblogs.com/wx491592452/p/ee480b1719f8404c8b0a640ed3604d2e.html