1. 程式人生 > >Java單元測試

Java單元測試

ltr func top code except false app https ini

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單元測試