alibaba / alibaba/testable-mock

被测试类的方法没有被mock

Open
#323 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

package cn.sunline.risk.management;

import com.alibaba.testable.core.annotation.MockMethod;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.stereotype.Component;

@SpringBootTest(classes = Application.class)
public class DemoTest {
@Autowired
private DemoService1 demoService1;

public static class Mock{

@MockMethod(targetClass = DemoService1.class)
public String test2(String x){
return "123";
}

@MockMethod(targetClass = DemoService1.class)
public String test3(String x){
return "456";
}

}

@Test
void testDemo2(){

System.out.println(demoService1.test1("a"));

}
@Test
public void Demo2(){

/*
String a = "zhao";
Mockito.when(demoService1.test2(a)).thenReturn("zhaoxiaowei_v");
Mockito.when(demoService1.test3(a)).thenReturn("zhaoxiaowei_v");

String s = demoService.test1(a);
System.out.println(s);
//Assert.assertEquals(demoService.test1(a),"zhaoxiaowei_v");
*/

}

}

@Component
class DemoService{
@Autowired
DemoService1 demoService1;

}
@Component
class DemoService1{

public String test1(String x){
System.out.println("*****"+x);
return test2(x);
}
public String test2(String x){
System.out.println("---1"+x);
return x ;
}

public String test3(String x){
System.out.println("---2"+x);
return x ;
}
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the DemoTest reproduction in the issue, especially testDemo2 and the @MockMethod methods targeting DemoService1. Run the Spring Boot test and verify whether calls from DemoService1.test1 to test2 or test3 are intercepted; done means the reported methods are mocked as expected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.