Spring: unit test for class that has both field & constructor injection
问题 I have below setup of classes. class Base { @Autowired private BaseService service; //No getters & setters .... } @Component class Child extends Base { private final SomeOtherService otherService; @Autowired Child(SomeOtherService otherService) { this.otherService = otherService; } } I am writing a unit test for the Child class. If I use @InjectMocks then the otherService comes out to be null. If I use, the constructor of Child class in the setup of the test, then the fields in Base class