# 一、使用@SpringBootTest测试
@SpringBootTest也可用于测试 Spring WebFlux 控制器,它会将整个应用启动,并注入WebTestClient ,CityWebFluxController以及它所依赖的CityHandler.
```java
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CityWebFluxControllerTest {
@Autowired
private WebTestClient webClient;
private static Map cityMap = new HashMap<>();
@BeforeClass
public static void setup() throws Exception {
City bj= new City();
bj.setId(1L);
bj.setProvinceId(2L);
bj.setCityName("BJ");
bj.setDescription("welcome to beijing");
cityMap.put("BJ", bj);
}
@Test
public void testSave() throws Exception {
City expectCity = webClient.post().uri("/city")
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromObject(cityMap.get("BJ")))