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);        
    }
    
}  

posted @ 2018-08-28 10:28  小学生II  阅读(1293)  评论(0编辑  收藏  举报