alibaba / alibaba/testable-mock

SSM框架下mock不生效

Open
#276 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
1.8k
Forks
306
PR merge metrics
No merged PRs in 30d

Description

```
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = XXX.class)
public class DemoTest {
@Autowired
ServiceA serviceA;
public static class Mock{
@MockInvoke(targetClass = JsonUtil.class)
private String toJson(AAo aAo){
return "123";
}
@MockInvoke(targetClass = ServiceB.class)
private String methodB(AAo aAo){
return "123";
}
}

@Test
public void test(){
AAo aAo= new AAo();
serviceA.methodA(aAo);
}
}

@Controller
@RequestMapping("/")
public class ServiceA{
@Autowired
private ServiceB serviceB;

@PostMapping("/")
@Override
public void methodA(AAo aAo){
logger.info(serviceB.methodB(aAo));
logger.info( JsonUtil.toJson(aAo));
}

}
```
tojson方法并没有被覆盖,serviceB的methodB方法也没有被覆盖

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the shown DemoTest with the ServiceA, ServiceB, and JsonUtil example, then trace how MockInvoke is applied under SpringJUnit4ClassRunner and SpringBootTest. Check both the static JsonUtil.toJson call and the autowired ServiceB.methodB call; done means both mocked methods return the demonstrated "123" value.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.