Junit 5 looking for actual environmental configuration to run the test

后端 未结 3 1159
夕颜
夕颜 2021-01-27 12:42

My project is using spring-boot, sping-data-jpa, spring-data-rest, hibernate

I have updated to spring boot 2.3.1

3条回答
  •  孤城傲影
    2021-01-27 13:47

    Firstly looking at your code you are injecting the mocks in to the test class rather than the actual service. Is this how your actual test looks or have you just copied this in so as to not share your actual code?

    @InjectMocks
    private MyServiceTest myServiceTest;
    

    Secondly this is a unit test so remove the @SpringBootTest annotation. It is adding unnecessary overhead and is probably causing the error through lack of configuration for code you are not actually testing having mocked the repository anyway.

提交回复
热议问题