mock打桩测试

pom依赖:

<!-- https://mvnrepository.com/artifact/org.jmockit/jmockit -->
<dependency>
    <groupId>org.jmockit</groupId>
    <artifactId>jmockit</artifactId>
    <version>1.48</version>
    <scope>test</scope>
</dependency>

测试代码:

@Test
    public void testRefundOrderQuery() {
        RefundOrderQueryFullRequest refundOrderQueryFullRequest = new RefundOrderQueryFullRequest();
        refundOrderQueryFullRequest.setRefundNo("10000001");
        
        new MockUp<UMPayOrderServiceImpl>() {
            @Mock
            public Map<String,Object> postAndParseData(String url,Map<String,Object> reqMap,Class<?> responseType){
                Map<String,Object> map = new HashMap<String,Object>();
                map.put("ret_code", "0000");
                return map;
            }
        };
        RefundOrderQueryFullResponse refundOrderQuery = umpayOrderServiceImpl.refundOrderQuery(refundOrderQueryFullRequest);
        assertEquals("0000",refundOrderQuery.getRetCode());
    }

 

posted on 2019-11-17 00:08  过来啊小莲  阅读(1064)  评论(0编辑  收藏  举报

导航