Springboot中Junit记录

Springboot中Junit记录

springboot的Junit, 找了下注解配置, 这里记录一下

@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SSOServiceApplication.class) //classes指定springboot的启动类
public class JunitTest {
@Autowired
private TestRestTemplate restTemplate; //通过TestRestTemplate进行controller的接口测试
@Autowired
RedisUtil redisUtil;
@Test
public void jendisTest() {
//ResponseModel responseModel = restTemplate.getForObject(URL, ResponseModel.class);
redisUtil.set(“20190949”,“test”, RedisConstants.datebase0);
Long resExpire = redisUtil.expire(“20190949”, 60, RedisConstants.datebase0); //设置key过期时间
String res = redisUtil.get(“20190949”, RedisConstants.datebase0);
log.info(“单元测试结果:{},key:{}”, res,“20190949”);
}

}

maven依赖
     
        org.projectlombok
        lombok
        1.16.16
    

    
        org.springframework.boot
        spring-boot-test
    

你可能感兴趣的:(记录)