整合junit测试
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
package com.ivan.test;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Main.class)
public class UserServiceTest {
@Autowired
private UserService userService;
@Test
public void testAdd(){
userService.add();
}
}
整合redis
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
server:
port: 8081
spring:
config:
activate:
on-profile: dev
data:
redis:
host: 127.0.0.1
port: 6379
@Autowired
private RedisTemplate redisTemplate;
@Test
public void testSet(){
redisTemplate.boundValueOps("name").set("zhangsan");
}
@Test
public void testGet(){
Object name= redisTemplate.boundValueOps("name").get();
System.out.println(name);
}