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