我用Spock编写了集成测试。已将Spring引导上下文配置为随机端口。Documantation声称,然后sprig应该向我注入正确配置的WebTestClient实例,但是当我试图调用那些“自动配置的实例时,我有下面的错误:
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:8080
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ Request to POST http://localhost:8080/sign-up [DefaultWebClient]下面是我的代码: BaseIntegrationTest
@SpringBootTest(webEnvironment = RANDOM_PORT, classes= Application.class)
@ContextConfiguration
@EnableConfigurationProperties
abstract class BaseIntegrationSpec extends Specification {使用WebTestClient类:
@Component
class WebTestClientWrapper {
@Autowired
private WebTestClient webTestClient
@Autowired
private ObjectMapper objectMapper发布于 2020-07-06 06:40:39
确保在开始测试时localhost:8080上的服务器已经在运行。WebTestClient假定外部服务器在绑定到服务器时正在运行。
https://stackoverflow.com/questions/62627911
复制相似问题