mock打桩测试
Posted vianzhang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()); }
以上是关于mock打桩测试的主要内容,如果未能解决你的问题,请参考以下文章