Junit
Junit.不用解释了吧,不知道的我只想说:出去。这篇我只简单介绍一下模拟request。后面陆续增加
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BeautyApplication.class)
@WebIntegrationTest
public class TestSign {
RestTemplate restTemplate = new RestTemplate();//测试http请求的
@Test
public void testSignUp(){
String url = "http://localhost:8080/sign/1";
Map map = new HashMap<>();
String result = restTemplate.getForObject(url, String.class, map);
System.out.print(result+"=========");
}
}
当然了,你要在maven里面配置上test
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
Json
在SpringBoot下,只要配置了JackJson,就会自己返回json了
<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.0.2</version>
</dependency>