zoukankan      html  css  js  c++  java
  • 配置文件application.properties剥离

    1、在resources目录下配置application.properties:

    test.url=http://127.0.0.1:8888
    getCookees.uri=/getCookies
    login=/login
    application.properties

    2、测试代码中使用,

    package httpclient;
    
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;
    
    import java.io.IOException;
    import java.util.Locale;
    import java.util.ResourceBundle;
    
    public class MyCookiesForGet {
        private String url;
        private ResourceBundle bundle;
    
        @BeforeTest
        public void beforeTest(){
            bundle = ResourceBundle.getBundle("application", Locale.CHINA);
            url = bundle.getString("test.url");
        }
        @Test
        public void testGetCookies() throws IOException {
            String result;
            //从配置文件中拼接测试url
            String uri = bundle.getString("getCookees.uri");
            String testUrl = this.url+uri;
            HttpGet get = new HttpGet(testUrl);
            HttpClient client = new DefaultHttpClient();
            HttpResponse httpResponse= client.execute(get);
            result = EntityUtils.toString(httpResponse.getEntity());
            System.out.println(result);
        }
    }
    配置文件在测试代码中使用
  • 相关阅读:
    C#调用WebService实现天气预报
    火狐完整版下载地址
    Unity3D 中 2D_Toolkit插件下载 和 导入方法
    给大家分享个 网站头像上传的 插件
    JQuery工具方法,实例方法
    ireport5.6.0 win10打不开
    JFreeChart 零散
    JS 类继承 原型继承
    技术电子书下载网址
    正则 变量替换
  • 原文地址:https://www.cnblogs.com/wangkc/p/10851217.html
Copyright © 2011-2022 走看看