【发布时间】:2019-04-18 14:31:57
【问题描述】:
@RestController
@RequestMapping("/api/v1/platform")
public class PlatformController {
@Autowired
private PlatformRepository platformRepository;
@GetMapping
public Flux<Platform> findAll() {
log.info("Calling findAll platforms");
return platformRepository.findAll();
}
}
@RunWith(SpringRunner.class)
@WebFluxTest
public class PlatformControllerTest {
@MockBean
private PlatformRepository platformRepository;
@Test
public void findAll() throws Exception {
WebTestClient client = WebTestClient.bindToController(new PlatformController()).build();
client.get()
.uri("/api/v1/platform")
.exchange()
.expectStatus().isOk();
}
}
上面我附上了我想要实现的简单 POC。我无法将模拟注入控制器进行测试并且测试失败。有没有其他方法可以做到这一点,还是我错过了一些基本概念?
【问题讨论】:
标签: java spring spring-boot spring-webflux project-reactor