使用gatling进行REST API测试:获取状态400

时间:2016-06-22 07:12:25

标签: rest gatling

我尝试使用测试REST API。

我在gatling脚本()中配置了所有内容,但我正在

  

11:54:41.466 [WARN ] i.g.h.a.ResponseProcessor - Request 'Top Speed' failed: status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 400

以下是我的代码。

package computerdatabase
import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.concurrent.duration._
class TopSpeedSimulation extends Simulation {
    val httpConf = http.baseURL("http://192.168.0.10:23180/highresvu")

  val headers_1 = Map("Content-Type" -> "application/vnd.com.wirelesscar.highresolution-vehicleutilization.hrvu.v1+xml")

  val scn = scenario("My Scenario") 
    .exec(http("Top Speed")
    .post("/topspeed")
    .headers(headers_1)
    .body(StringBody("""{"highResVehicleUtilization":
              {"-xmlns": "http://wirelesscar.com/highresvu/highresvehicleutilization/1_0","request":{"vehicleDetails":{"vin": "RIGUD000000000057","chassisId":"RIGUD-000057"},"driveSessions":{ "driveSessionId": "1460453954" },"duration":{"fromDate": "2016-05-27T10:30:10.000Z","toDate": "2016-05-16T10:55:10.000Z"}}}}"""))
    )
  setUp(scn.inject(atOnceUsers(5)).protocols(httpConf))
}

1 个答案:

答案 0 :(得分:1)

启用以下记录器启用记录请求和响应:

    <logger name="io.gatling.http.ahc" level="DEBUG" />
    <logger name="io.gatling.http.response" level="DEBUG" />

然后您将看到正在发出的查询和失败响应。 e.g。

=========================
HTTP request:
GET http://myapp/endpoint?course=173.125183%E2%80%A8
headers=
Connection: keep-alive
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Host: myapp
=========================
HTTP response:
status=
400 Bad Request
headers=
Server: nginx/1.8.1
Date: Mon, 27 Jun 2016 04:55:59 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 95
Connection: keep-alive

body=
The query parameter 'course' was malformed:
'173.125183
    ' is not a valid floating point value
<<<<<<<<<<<<<<<<<<<<<<<<<