Mockito单元测试
程序员文章站
2022-04-30 12:45:15
...
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
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.test.context.junit4.SpringJUnit4ClassRunner;
import static org.mockito.ArgumentMatchers.any;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
@Slf4j
public class UserInfoKeeperTest {
@Autowired
@InjectMocks
private TestServiceImpl testServiceImpl;
@Autowired
@MockBean
SayHelloApi sayHelloApi;
@Before
public void before(){
MockitoAnnotations.initMocks(this);
Mockito.when(sayHelloApi.say(any(SayReq.class))).thenReturn("java world");
}
@Test
public void testMqConfig() {
String loginRes = testServiceImpl.login();
log.info("============================================="+loginRes);
}
}
上一篇: MYSQL5.7的安装(yum、二进制、编译安装)
下一篇: 恶搞吹笛子的人,你要不要也试试?
推荐阅读
-
浅谈如何提高PHP代码质量之单元测试
-
单元测试工具记录 单元测试
-
maven 小结(打包和单元测试)
-
Java学习记录:纠错Junit单元测试遇到的initializationerror:method initializationerror not found
-
使用junit进行单元测试时报错Invalid bound statement (not found)
-
initializationError 单元测试错误
-
IDEA 单元测试报错:Class not found:xxxx springboot
-
PHP单元测试利器:PHPUnit深入理解(1)_PHP教程
-
java单元测试JUnit框架原理与用法实例教程
-
浅谈maven单元测试设置代理