alibaba / alibaba/testable-mock

把Mock类移到另外的包中,代理规则就变了

Open
#299 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.8k
Forks
306
PR merge metrics
No merged PRs in 30d

Description

我git了源码,jdk改为1.8
把CookerServiceMock改为public,然后运行了java-demo中的SellerServiceTest,正常测试通过

但是当我把CookerServiceMock移到com.alibaba.demo.mock包下,
在SellerServiceTest中加了@MockWith(CookerServiceMock.class),
然后神奇的事情发生了,should_sell_sandwich测试失败
```
org.opentest4j.AssertionFailedError:
Expected :Fake-Sandwich-Cooker & Faked-Sandwich
Actual :Real-Sandwich-Cooker & Real-Sandwich
```
我查看了日志,hireSandwichCooker和cookSandwich没有used的记录

后来我测试了一下,当我在代码中加入
```
@MockInvoke(targetClass = CookerService.class)
private String prepareSandwich() {
return "prepareSandwich";
}
```
prepareSandwich有used日志

所以代理的规则是怎么样的,什么时候替换是生效,嵌套调用的生效范围是?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with java-demo/SellerServiceTest and the CookerServiceMock example, then inspect how @MockWith and @MockInvoke are applied when the mock class moves to com.alibaba.demo.mock. Reproduce should_sell_sandwich and compare the used logs for hireSandwichCooker, cookSandwich, and prepareSandwich. Done means the proxy and nested-call scope are explained and the reported behavior is either corrected or documented.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.