Httpclient test

Swagger is an online interface document. Although it can be used for testing, it requires a browser to enter Swagger. The most important thing is that it cannot save test data.

There is a very convenient http interface testing tool httpclient in IDEA. The following describes how to use it. We will use it for interface testing later.

If the IDEA version is lower and does not come with httpclient, you need to install the httpclient plug-in.

Enter the controller class and find the method corresponding to the http interface

 

Click Generate request in HTTP Client to generate a test case.

 

You can see that you have generated a file ending with .http

We can add request parameters for testing

After adding the parameters, you can run it

 

Observe the console and the test passes.

http://localhost:63040/course/list?pageNo=2&pageSize=10

HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 07 Sep 2022 00:54:50 GMT
Keep-Alive: timeout=60
Connection: keep-alive

{
  "items": [
    {
      "id": 88,
      "companyId": 1232141425,
      "companyName": null,
      "name": "1",
      "users": "1",
      "tags": "1",
      "mt": "1-1",
      "mtName": null,
      "st": "1-1-1",
      "stName": null,
      "grade": "204001",
      "teachmode": "200002",
      "description": "1",
      "pic": "http://r3zc5rung.hd-bkt.clouddn.com/cb1b6038-ef68-4362-8c29-a966886d1dc5sakUiFHLb5sRFdIK",
      "createDate": "2021-12-27 20:14:53",
      "changeDate": "2021-12-27 20:28:58",
      "createPeople": null,
      "changePeople": null,
      "auditStatus": "202002",
      "auditMind": null,
      "auditNums": 0,
      "auditDate": null,
      "auditPeople": null,
      "status": 1,
      "coursePubId": null,
      "coursePubDate": null
    },
   ....
  ],
  "counts": 14,
  "page": 2,
  "pageSize": 10
}
Response file saved.
> 2022-09-07T085450.200.json

Response code: 200; Time: 392ms (392 ms); Content length: 1916 bytes (1.92 kB)

 

The .http file is a test case document. It can be saved along with the project project, so that the test data can be saved to facilitate testing.

In order to save .http files conveniently, we create a separate directory in the root directory of the project to store them separately.

We create .http files in units of modules.

 

 Open the http file of the content management module and copy the test data just now.

In order to facilitate future integration testing with the gateway, here we configure the test host address in the configuration file http-client.env.json

 

Note: The file name http-client.env.json remains consistent, otherwise the contents of the dev environment variable cannot be read.

The content is as follows:

{
  "dev": {
    "access_token": "",
    "gateway_host": "localhost:63010",
    "content_host": "localhost:63040",
    "system_host": "localhost:63110",
    "media_host": "localhost:63050",
    "search_host": "localhost:63080",
    "auth_host": "localhost:63070",
    "checkcode_host": "localhost:63075",
    "learning_host": "localhost:63020"
  }
}

 Go back to the xc-content-api.http file and replace http://localhost:63040  with a variable

 

 

Guess you like

Origin blog.csdn.net/qq_46020806/article/details/132561071