testable-mock icon indicating copy to clipboard operation
testable-mock copied to clipboard

子类中修改父类的变量报错

Open hugo666-code opened this issue 5 years ago • 4 comments

PrivateAccessor.set(new ReceiveBillManagerImpl(), "mongoOperations", MongoTestUtils.getMongoOperations());

ReceiveBillManagerImpl的父类里有一个protected修饰的变量mongoOperations 想使用PrivateAccessor进行赋值,但是编译期报错Error:java: com.alibaba.testable.processor.exception.MemberNotExistException: Field "mongoOperations" not exist in class "ReceiveBillManagerImpl"

是不是TestableMock只能对private 修饰的变量进行修改,protected修饰的不行

hugo666-code avatar Feb 18 '21 06:02 hugo666-code

问题收到,当前的编译期检查功能确实对父类成员没做好适配,下个版本里会提供一个绕过方案,预计在0.5.1版本做正式修复

linfan avatar Feb 18 '21 07:02 linfan

@hugo666-code 刚发现绕过方案在0.4.12版本已经发了😆,把@EnablePrivateAccess注解的verifyTargetOnCompile参数值设置成false就行: https://alibaba.github.io/testable-mock/#/zh-cn/doc/private-accessor?id=私有成员编译期校验

如果只是用PrivateAccessor工具类的话,也可以直接把@EnablePrivateAccess注解去掉,也会禁用编译期校验

linfan avatar Feb 19 '21 09:02 linfan

正式修复将包含在0.5.2版本中

linfan avatar Mar 11 '21 06:03 linfan

0.5.2版本已发布

linfan avatar Mar 13 '21 03:03 linfan