alibaba / alibaba/testable-mock
间接mock静态方法失效
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
版本:0.6.7
``` java
//// 类A
public class MethodA {
public String handle () {
return UtilB.getInfo("aaa");
}
}
//// 类B
public class UtilB {
public static String getInfo (String url) {
return url + InnerUtilC.rawInfo();
}
}
//// 类C
public class InnerUtilC {
public static String rawInfo () {
return "RAW";
}
}
//// 测试方法
public class MethodATest {
private MethodA methodA = new MethodA();
@Test
public void handle() {
System.out.println(methodA.handle());;
}
}
//// mock类,和MethodATest在同个包下
public class MethodAMock {
@MockMethod(targetClass = InnerUtilC.class)
public static String rawInfo () {
return "mock raw";
}
}
```
问题描述:类A调用类B的静态方法,类B的静态方法实际调用类C的方法,但mock类C的静态方法时,并没有生效
预期结果:打印-> aaa mock raw
实际结果:打印-> aaaRaw
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the example on version 0.6.7 using MethodA, UtilB, InnerUtilC, and MethodAMock, focusing on the indirect static call from UtilB to InnerUtilC. Trace the static mocking behavior for the @MockMethod target and compare it with the direct-call case. Done means MethodA.handle() produces "aaa mock raw" instead of "aaaRaw".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100