我这边在做单元测试,测试代码覆盖率的时候准备模拟一个方法的返回,但是模拟不生效:
工具类:
@Component
@Slf4j
public class routerutil {
public static final string piccycpt = “picc-ycpt";
public static final string URL_GETCOMCODE =“/common/getCwComCode";
public static final string cW_coM_CoDE =“cwComCode";
@Autowired
private PiccRouteProperty piccRouteProperty;
@Autowired
private RestTemplateUtil restTemplate;
public ApiResponse doPostForobj(string value, string url) {
JSONObject param = new JSONObject();
param.put("comCode",value);
return restTemplate.postForobj(param, url, Apiresponse.class);
}
测试类:
public class RouterUtil_bakTest {
private Routerutil routerUtil = new RouterUtilo);
private RestTemplateUtil restTemplate = new RestTemplateUtil();
private ApiResponse apiResponse = new Apiresponse();
@Test
public void doPostForobjTest() {
try {
Mapstring> testMap = new HashMap<>();
testMap.put("test","test");
apiresponse.setData(testMap);
Mockito.when(restTemplate.postForObj(Mockito.any(JSONObject.class),Mockito.anystringO,Mockito.anyO))).thenreturn(apiResponse);
//Class[] paramTypes =new Class[]{Object.class,string.class,Class.class};
//PowerMockito.stub(PowerMockito.method(RestTemplateUtil.class,"postFor0bj",paramTypes)).toreturn(apiResponse);
//PowerMockito.when(restTemplate.postFor0bj(RestTemplateUtil.class,"postForObj",Mockito.any())).thenReturn(apiresponse);
Apiresponse result = routerUtil.doPostForObj( value: "test", url: "test");
}catch (Exception e){
e.printstackTrace(();
}
这种类型的测试是为了确认最终产品是否按照规范工作。功能性测试人员主要寻找游戏或其图形和用户界面中的一般问题,例如:游戏资产完整性、稳定性问题、视听问题和游戏机制问题。熟练的游戏测试人员在测试交互式应用程序时很少会考虑到诸如冻结、崩溃和进程阻塞之类的性能问题。用户界面(UI)测试,在另一方面,确保用户友好的游戏。UI测试的关键在于突出两个重要的东西,即内容类型和图形元素。此外,游戏的本地化测试也应包括在内。