【发布时间】:2019-06-14 19:57:51
【问题描述】:
我想在我的测试中使用 WebTestClient。像这样工作:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
public class ControllerTest {
@Autowired
private WebTestClient webTestClient;
@Test
public void webtestClient () {
assertNotNull(webTestClient);
}
}
但是现在我想将 WebTestClient 注入到一个辅助类中:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
public class ControllerTest {
@Autowired
private Helper helper;
@Test
public void webtestClient () {
helper.check();
}
}
@Component
public class Helper {
@Autowired
private WebTestClient webTestClient;
public void check() {
assertNotNull(webTestClient);
}
}
也有效。但 Intellij 显示错误:
无法自动接线。未找到“WebTestClient”类型的 bean。更多的... (Strg+F1)
新信息:测试在 Intellij 中运行良好,但在使用 maven 时运行良好。
这是一个有问题的测试项目: https://github.com/kicktipp/demo
如何在 Helper 类上使用 WebTestClient?
【问题讨论】:
-
看起来像一个错误。请在 YouTrack 上报告问题:youtrack.jetbrains.com/issues/IDEA
-
感谢您的评论。我在这里创建了一个问题:youtrack.jetbrains.com/issue/IDEA-205789
标签: java spring spring-boot testing intellij-idea