接口测试学习笔记<一>

暂未整理脱水

  1. Java语法,Idea提示Usage of API Documented as @since 1.6+
    解决方案:File->Project structure->module->source->language Level 改为1.6+版本

  2. Java语法,接1。改完后编译失败,提示javacTask:源发行版1.6,需要目标发行版1.6
    解决方案:File->Settings->Build,Execution,Deployment->Complier->Java Complier->改为1.6+

  3. testNG执行顺序
    用例中有2个case需要顺序执行。按照很多教程写了preserve-order="true"发现并没有用……为什么需要查证。解决方法是给第二顺序执行的case加上@Test(dependsOnMethods = {"testname"}解决。

  4. httpspost:

public static String HttpsPost(String url, Object obj){    
 HttpClient httpClient = new DefaultHttpClient();    
 X509TrustManager xtm = new X509TrustManager() {        
   public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
   }        
   public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {        
   }        
   public X509Certificate[] getAcceptedIssuers() {
     return null;        
   }    
 };    
 try {        
   SSLContext ctx = SSLContext.getInstance("SSL");        
   ctx.init(null, new TrustManager[]{xtm}, null);        
   SSLSocketFactory socketFactory = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
   httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, socketFactory));        
   HttpPost httpPost = new HttpPost(url);        
   StringEntity se = new StringEntity(JSON.toJSONString(obj), StandardCharsets.UTF_8);        
   httpPost.setEntity(se);        
   HttpResponse rep = httpClient.execute(httpPost);        
   HttpEntity entity = rep.getEntity();        
   if(null != entity){            
     String responseContent = EntityUtils.toString(entity, "UTF-8");                  
     System.out.println(responseContent);            
     return responseContent;        
   }        
   return null;    
 } catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {        
   e.printStackTrace();        
   return null;    
 }
}

你可能感兴趣的:(接口测试学习笔记<一>)