alibaba / testable-mock

换种思路写Mock,让单元测试更简单
https://alibaba.github.io/testable-mock/
MIT License
1.83k stars 310 forks source link

when use MockWith annotation, mockClass not right #315

Open winstonczc opened 1 year ago

winstonczc commented 1 year ago
TestableClassTransformer#lookForMockWithAnnotationAsSourceClass
->
TestableClassTransformer#parseMockWithAnnotation
...
if (isExpectedType(cn.name, type, expectedType)) {
   Type clazz = AnnotationUtil.getAnnotationParameter(an, ConstPool.FIELD_VALUE,
   Type.getType(NullType.class), Type.class);
   DiagnoseUtil.setupByClass(ClassUtil.getClassNode(clazz.getClassName()));
   return clazz.getClassName();
}
...

clazz.getClassName() should be converted to vm className

linfan commented 1 year ago

Could you provide more details or a test case to show why this mock class is incorrect ?

winstonczc commented 1 year ago

className should be converted to slash format in method TestableClassTransformer#lookForMockWithAnnotationAsTestClass before return ,like:com/xxx/xxx