【SpringBoot】单元测试

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class TestUserController {
    @Autowired
    private TestRestTemplate restTemplate;
    @Test
    public void get() throws Exception {
        MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
        map.add("phone", "xxx");
        String result = restTemplate.postForObject("/my/sendCode", map, String.class);
        System.out.println(result);
    }
}
原文地址:https://www.cnblogs.com/cnsec/p/13286694.html