mockito怎么mock一个类的私有属性?
@InjectMocks
private UserServiceImpl userService;
@Test
public void test() throws NoSuchFieldException{
Field apiField = UserServiceImpl.class.getDeclaredField("username");
FieldSetter.setField(userService, apiField, "1");
}
如上,已经为UserServiceImpl类的username属性成功设置值:1