In 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< Span class= "Hljs-tag" ></version> <!--<scope> Test</scope>--></DEPENDENCY>
Createtest:
Class above plus:
@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:applicationContext.xml")@Transactional@TransactionConfiguration(defaultRollback = false)
Class inside Add:
@Beforepublic void setUp() throws Exception {ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");SpringBeanUtil.initContext(context);}
Global variables that need to be set:
SessionContext.setTenantId(100000000001L); // 全局租户SessionContext.setOpId(100000000001L); // 全局操作员idSystem.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 Unit Test