alibaba / alibaba/testable-mock

mock 没有生效

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

Description

有没有交流群呢、
mock没有生效
没有 Found method xxx used 日志、还有什么检查方法呢
利用@MockWith 使用mock容器、但是没有发生替换

---

其中Line XX, mock method "XXX" used日志展示了被测类中所有发生了Mock替换的调用和相应代码行号。

依据需排查的测试类,进行针对性排查。假设被测类为"com.demo.BizService",测试类为"com.demo.BizServiceTest",Mock容器类为"com.demo.BizServiceTest.Mock":

若该日志文件未生成,请检查pom.xml或build.gradle配置是否正确引入了TestableMock依赖
若日志中只能找到com/demo/BizServiceTest$Mock,没有找到被测类和测试类,请检查Mock容器类的名称和位置是否符合规范
若日志中找到了Mock类和测试类,但没有找到被测类com/demo/BizService,请检查被测类与测试类是否包路径相同,且名称为"被测类+Test",或者是否正确的使用了@MockWith注解
若日志中三个类都已经找到,且有Found method xxx,但预期的代码行位置没有发生Mock替换,请继续检查Mock方法定义是否未与目标方法匹配

---

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reported @MockWith setup and inspect the pom.xml or build.gradle dependency configuration. Reproduce the missing mock replacement and check whether the generated log contains the mock container, test class, and target class entries described in the issue. Done means identifying the missing configuration, naming, package, annotation, or method match, with a confirmed diagnostic result.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.