Custom parameter length when HttpClient does interface test
When doing http interface testing, you always have to do a lot of parameters and values, and the whole interface looks quite awkward, so you put the combination of parameters into one method and the execution into one method, and the main function just needs to get the response string to do processing and make assertions, so this code looks much cleaner, and the jar packages of httpclient, dom4j and testng are used here.
Import java.io.IOException
Import java.io.UnsupportedEncodingException
Import java.util.ArrayList
Import java.util.List
Import org.apache.http.HttpEntity
Import org.apache.http.NameValuePair
Import org.apache.http.client.ClientProtocolException
Import org.apache.http.client.entity.UrlEncodedFormEntity
Import org.apache.http.client.methods.CloseableHttpResponse
Import org.apache.http.client.methods.HttpPost
Import org.apache.http.impl.client.CloseableHttpClient
Import org.apache.http.impl.client.HttpClients
Import org.apache.http.message.BasicNameValuePair
Import org.apache.http.util.EntityUtils
Import org.dom4j.Document
Import org.dom4j.DocumentException
Import org.dom4j.DocumentHelper
Import org.dom4j.Element
Import org.testng.AssertJUnit
Public class HttpInterfaceTest {
Private static String url
Private static String [] [] keyVlaueList = {{"cdkey", "6SDK"}, {"password", "160489"}}; / / customize the number and values of API parameters as needed
Private static List postPara = new ArrayList ()
Private static String responseEntiy
/ * *
* Assembly request parameters
* @ param keyVlaueList
, /
Public static List getPostPara (String [] keyVlaueList) throws DocumentException {
For (int I = 0 position I)