WebTestClient在@SpringBootTest中自动连接时为空

WebTestClient在@SpringBootTest中自动连接时为空,spring,spring-boot,spring-test,spring-boot-test,webtestclient,Spring,Spring Boot,Spring Test,Spring Boot Test,Webtestclient,我的Spring Boot应用程序在2.4.2版上运行。我正在尝试为用户注册设置集成测试。此测试类从定义一些静态设置的AbstractIntegrationTest扩展而来 启动测试时,webTestClient为null。我试图添加@AutoConfigureWebTestClient,但问题仍然存在 你知道这里可能缺少什么吗 RegistrationIT.java 公共类注册扩展了AbstractIntegrationTest{ @自动连线 私有WebTestClient WebTestCl

我的Spring Boot应用程序在2.4.2版上运行。我正在尝试为用户注册设置集成测试。此测试类从定义一些静态设置的
AbstractIntegrationTest
扩展而来

启动测试时,
webTestClient
null
。我试图添加
@AutoConfigureWebTestClient
,但问题仍然存在

你知道这里可能缺少什么吗

RegistrationIT.java

公共类注册扩展了AbstractIntegrationTest{
@自动连线
私有WebTestClient WebTestClient;
@试验
public void shouldRegisterNewUser()抛出JSONException{
String requestBody;//一些JSON
webTestClient
.post()
.uri(“/api/user”)
.body(BodyInserters.fromValue(requestBody))
.exchange()
.expectStatus().isOk();
}
}
AbstractIntegrationTest.java

@SpringBootTest(webEnvironment=SpringBootTest.webEnvironment.RANDOM\u端口)
@ActiveProfiles(“集成测试”)
@测试容器
公共抽象类AbstractIntegrationTest{
私有静态最终字符串MARIADB\u IMAGE\u NAME=“MARIADB:10.4.16”;
私有静态最终字符串MARIADB\u DATABASE\u NAME=“test\u db”;
私有静态最终字符串MARIADB\u USERNAME=“test\u user”;
私有静态最终字符串MARIADB\u PASSWORD=“test\u pass”;
静态最终MariaDBContainer MariaDBContainer=(MariaDBContainer)新的MariaDBContainer(MARIADB\u IMAGE\u NAME)
.withDatabaseName(MARIADB_数据库_名称)
.withUsername(MARIADB_用户名)
.withPassword(MARIADB_密码)
.重复使用(真实);
静止的{
mariaDBContainer.start();
}
@动态属性源
静态无效注册表属性(DynamicPropertyRegistry注册表){
add(“spring.datasource.url”,mariaDBContainer::getJdbcUrl);
add(“spring.datasource.username”,mariaDBContainer::getUsername);
add(“spring.datasource.password”,mariaDBContainer::getPassword);
}
}

调试后,我发现我使用了JUnit4中的
@Test
注释,而不是JUnit5。更正
import
语句后,测试成功运行。

为什么类注册是抽象的?也许这就是原因?对不起,这是复制粘贴错误。我更新了描述。