Java 依赖注入在SpringBoot和Junit 5集成测试中不起作用

Java 依赖注入在SpringBoot和Junit 5集成测试中不起作用,java,spring,spring-boot,junit,junit5,Java,Spring,Spring Boot,Junit,Junit5,接下来,我正在与SpringBoot和Junit5建立一个集成测试 但是当我在没有@RunWith(SpringRunner.class)的情况下运行这个测试文件时,注释给出了NullPointerException,因为没有注入RecordService @ExtendWith(SpringExtension.class) @SpringBootTest @DefaultTestAnnotations // This is my meta-annotations public class Re

接下来,我正在与SpringBoot和Junit5建立一个集成测试

但是当我在没有
@RunWith(SpringRunner.class)
的情况下运行这个测试文件时,注释给出了NullPointerException,因为没有注入RecordService

@ExtendWith(SpringExtension.class)
@SpringBootTest
@DefaultTestAnnotations // This is my meta-annotations
public class RecordServiceImplTest {

    @Autowired
    private RecordService recordService; // This is null.

    @Test
    public void whenSearchParametersAreProvided_ItShouldGetTheGoldenRecord() throws MdmMatchServiceException {
        GoldenRecordDTO searchParams = new GoldenRecordDTO();
        searchParams.setCountryCode("CN");
        searchParams.setName("neeraj");
        assertNotNull(recordService.getGoldenRecord(searchParams));
    }
}

运行集成测试是否必须使用
@RunWith(SpringRunner.class)
?我怀疑您导入了JUnit4注释
org.junit.Test
而不是JUnit5注释:
org.junit.jupiter.api.Test

您还可以粘贴这个测试类的导入部分吗?