Spock - Mock private field
问题 I have to mock private field: public class A{ private final B b; public A(){ this.b = new B(new OtherService) } public test(){ int i = b.test() if(i == 0) b.test1() else b.test2() } } and I have to create unit tests for methods in this kind of class and I have to mock class B is it even possible here? 回答1: Please read my remarks here and here or in many other questions of this kind I answered concerning dependency injection (DI). The lack thereof in your tightly coupled application design is