Java单元测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java单元测试相关的知识,希望对你有一定的参考价值。
pom.xml中:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.6.RELEASE</version>
<!--<scope>test</scope>-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<!--<scope>test</scope>-->
</dependency>
createTest:
类上面加:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
@Transactional
@TransactionConfiguration(defaultRollback = false)
类里面加:
@Before
public void setUp() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
SpringBeanUtil.initContext(context);
}
需要设置的全局变量:
SessionContext.setTenantId(100000000001L); // 全局租户
SessionContext.setOpId(100000000001L); // 全局操作员id
System.setProperty("MQ_HOST_LIST","192.168.70.250");
System.setProperty("MQ_USER_NAME","admin");
System.setProperty("MQ_PASS_WORD","123456");
System.setProperty("hub.configure.type","DataBase");
以上是关于Java单元测试的主要内容,如果未能解决你的问题,请参考以下文章