2015-01-10 71 views
1

什麼是使用機器人框架用於測試使用JSON媒體類型(面向或資源)一個CRUD Web服務最簡單的方法?與機器人框架測試CRUD Web服務

閱讀互動:

GET /user/666 HTTP/1.1 
Host: example.com 


HTTP/1.1 404 Not Found 

創建互動:

POST /user HTTP/1.1 
Host: example.com 
Content-Type: application/json 

{ 
    "firstname":"Webber", 
    "lastname":"Jim" 
} 


HTTP/1.1 201 OK 
Content-Type: application/json 

{ 
    "id": 9780596805821, 
    "firstname":"Webber", 
    "lastname":"Jim" 
} 

回答

1

人們可以使用standard librariesrobotframework-requests像這樣:

*** Settings *** 
Library  Collections 
Library  OperatingSystem 
Library  RequestsLibrary 

*** Test Cases **** 
Create User 
     Create Session  example http://example.com 
    ${file_data}= 
    ... Get Binary File  ${RESOURCES}${/}normal_user.json 
    ${headers}= 
    ... Create Dictionary Content-Type application/json 
    ${resp}= 
    ... Post Request  example /user data=${file_data} headers=${headers} 
     Should Be Equal As Strings 
      ...    ${resp.status_code} 201 
     Dictionary Should Contain Key 
      ...    ${resp.json()}  id