码迷,mamicode.com
首页 > 移动开发 > 详细

配置文件application.properties剥离

时间:2019-05-12 10:45:58      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:close   methods   int   private   resources   hid   文件中   ack   ide   

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);
    }
}
配置文件在测试代码中使用

 

配置文件application.properties剥离

标签:close   methods   int   private   resources   hid   文件中   ack   ide   

原文地址:https://www.cnblogs.com/wangkc/p/10851217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!