接口测试学习笔记<一>

暂未整理脱水

  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;    
 }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • apache下的httpclient工具可大大简化开发过程中的点对点通信,本人将以微信多媒体接口为例,展示http...
    划破的天空阅读 5,353评论 0 32
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,785评论 18 399
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • 该文仅对于中间这种支付方式有参考价值哟 一、开发背景 在微信公众号中,需要进行微信支付且为微信公众号网页支付。 二...
    英文名叫夏天阅读 1,885评论 0 7
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,593评论 0 17