Spatis service单元测试: 使用mock mapper的方式

转载:https://blog.csdn.net/atec2000/article/details/54346242

@RunWith(MockitoJUnitRunner.class)
public class OrderServiceTest {

@InjectMocks
    private OrderServiceImpl service;
    
    @Mock
    private OrderMapper orderMapper;
    
    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);  
    }

@Test
    public void testControllerTest() throws Exception {     
    OrderPo orderPo = new OrderTruePo();
    orderPo.setOrderCustomer(1l);
        Mockito.when(orderMapper.getOrderPoByOrderId(any(Long.class))).thenReturn(orderPo);
        
    service.getOrderPoByOrderId(0l);        
    }
    
}

上一篇:【解决】 新浪sae固定链接404 问题


下一篇:【网站开发】在新浪SAE上搭建一个博客