API • Apache License Java library for testing of REST based services. Supports standard HTTP requests types and can be used to validate and verify the response of these requests. Pros • Extensive Java skills requires /Java lib only • No guidelines for tests • Code-as-a-test Cons
strict RESTful service test guidlines • Lower entry level for new QA engineers • Adopt spec-as-a-test approach with plain text used as definition language Cucumber wrapper for REST-assured library with additional step definition and features Why?
Testing Engine provider • REST-assured Testing Engine by default. Possibility to switch providers with no effect on end users • Internal Utilities for JSON, XML processing as well as file API and Tempting engine • Support for custom Recipes and additional functions defined by Testing Engine • Plugin system adds hooks for other developers to add custom project specific logic to the brew
<dependency> <groupId>lv.ctco.cukesrest</groupId> <artifactId>cukes-rest</artifactId> <version>X.X.X</version> <scope>test</scope> </dependency> Java Project Non-Java Project • xxx-cukes submodule for API tests inside main project • Separate Maven or Gradle project
what is desired In order to realize a named business value As an explicit system actor I want to gain some beneficial outcome which furthers the goal Additional text... Background: everything in place Scenario: Some determinable business situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too Scenario: A different situation ... my.feature
is desired In order to realize a named business value As an explicit system actor I want to gain some beneficial outcome which furthers the goal Additional text... Background: everything in place Scenario: Some determinable business situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too Scenario: A different situation ... my.feature
some precondition When some action by the actor Then some testable outcome is achieved Given some other precondition When some other action by the actor Then something else we can check happens too
performs GET request on http://localhost:4567/hello Then status code is 200 @Test public void serverReturnsOkStatusCode() throws Exception { when().get(“http://localhost:4567/hello"). then().statusCode(200); } REST-assured Inspired by REST-assured naming conventions
is http://localhost:4567 Scenario: Server returns OK status code When the client performs GET request on /hello Then status code is 200 Scenario: Server greets user When the client performs GET request on /hello Then response equals to "Hello World" Scenario: Server greets user by name Given queryParam "name" is "John" When the client performs GET request on /hello Then response contains "John"
{(person_name)} is John And queryParam "name" is "{(person_name)}" When the client performs GET request on /hello Then response contains "{(person_name)}" Variable names - alphanumeric (\w+)
by ID Given request body from file customers/json/newCustomer.json When the client performs POST request on /customers Then status code is 201 And header Location end with pattern customers/(.+) And let variable “{(location)}" equal to header Location When the client performs GET request on {(location)} Then status code is 200 And response contains properties from file customers/json/newCustomer.json
request body from file C://files/my.txt Given request body: """ [ “id”: “1” ] """ Given resources root is C://files/ Given request body from file my.txt
"Smith" } my.json Scenario: Request Body Given variable {(client_ID)} is 1 Given resources root is src/test/resources/ Given request body from file my.json …
the client performs GET request on {(location)} Then status code is 200 And response body contains property ”name” equal to “John” responseBody { "id" : 1, "name" : "John" }
When the client performs GET request on {(location)} Then status code is 200 And response contains properties from file customers/json/updatedCustomer.json { "name" : "Smith" } updatedCustomer.json responseBody { "id" : 1, "name" : "Smith" } Match everything by JSONPath