0

I am using Spring-Boot 2.5 and JUnit 5.

In a test class I have a bean (MyClass) that I need to inject some mocks and hence I use @InjectMocks.

@SpringBootTest
public class MyClassTest {

    //@Autowired
    @InjectMocks
    private MyClass myClass;

    @MockBean
    private MyOtherClass myOtherClass;

    ...

}

Is the @Autowired annotation implicit/required in the example above (a @SpringBootTest)? What is the effect with or without it for the application context.

dariosicily
  • 2,691
  • 2
  • 7
  • 14
Gabriel Petrovay
  • 18,575
  • 19
  • 87
  • 153
  • i think there are pretty good replies here: https://stackoverflow.com/questions/34067956/how-to-use-injectmocks-along-with-autowired-annotation-in-junit – Dmitrii Bocharov Oct 26 '21 at 13:18

0 Answers0