流水线的单元测试 代码没有覆盖到,使用的是Mockito测试框架,原来是Mockito没有正确使用
package com.hmdp;
import com.hmdp.controller.BlogController;
import com.hmdp.entity.Blog;
import com.hmdp.service.IBlogService;
import com.hmdp.service.impl.BlogServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @Author: ldj
* @Date: 2023/07/05/20:39
* @Description: Mockito 测试案例
*/
@RunWith(MockitoJUnitRunner.class)
@SpringBootTest
public class MockitoTest {
//我是主对象
@InjectMocks
private BlogController blogController = new BlogController();
//我是依赖对象,将被注入到主对象
@Mock
private IBlogService blogService = new BlogServiceImpl();
@Test
public void saveBlogTest(){
Blog blog = new Blog();
blog.setId(4657558585L);
blog.setName("java入门到进阶");
blogController.saveBlog(blog);
}
}