galatea-associates / fuse-starter-java

Starter project for Galatea java projects
17 stars 73 forks source link

Use Cucumber tests with a DSL for testing REST APIs #195

Open paulo-reichert opened 6 years ago

paulo-reichert commented 6 years ago

Issue Description

https://cucumber.io/

Design

[Description of the root cause for the issue and how to resolve it. Should be complete before Review is approved]

Test Evidence

[include relevant tests and output. Should be complete before Review is approved]

Validation in Develop -- [Proof issue is resolved in Develop. Should be complete before Issue is closed]

GalateaRaj commented 6 years ago

I'm looking to establish a DSL on top of cucumber for testing the behavior of REST APIs (independent of their functional domain).

Within the context of the REST DSL: The "Given" expressions help set up the HTTP request to be performed The "When" expression tells mockmvc (or resttemplate in the future for integration testing) to perform the request The "Then" expressions validate the response

Note that we may also have application specific "Given" expressions outside of the context of this REST DSL that initialize other state per standard BDD (e.g. initial values in a database, mocking out an external rest service).

Here are some example steps that I think we should support:

Givens (naturally, none of these are required)

  1. Given header "http-user" with value "raj"
  2. Given contentType is "application/json"
  3. Given acceptedType is "application/json"
  4. Given baseUri is "http://foo.nl:8000" (we don't usually use this for mockmvc but will be useful for rest template)
  5. Given queryParam is "?id=1232"
  6. Given requestBody is doc_string (see gherkin definition of doc strings)
  7. Given requestBody from file "resources/derp.json"

When (required)

  1. When we perform a GET on "/settlementEngine/mission" (POST, PUT, PATCH, DELETE also supported)

Then (not all required)

  1. Then status code is 200
  2. Then header "ETag" is "abcsdfs"
  3. Then contentType is "application/json"
  4. Then responseBody is doc_string (see gherkin definition of doc strings)
  5. Then responseBody matches file "resources/derp.json"
  6. Then responseBody matches jsonpaths datatable_of_json_path_and_value (note that spring boot already comes with json path implementation)

This will be a very powerful tool that multiple projects can benefit from.

On a somewhat related note, it would be good if we could demonstrate how to use a background section in a feature file.

paulo-reichert commented 6 years ago

We should have a look at Groovy's for DSL authoring: http://www.groovy-lang.org/

GalaFirsh commented 6 years ago

Maybe can use this?
cukes-rest: Cucumber DSL for testing RESTful Web Services https://github.com/ctco/cukes

GalateaRaj commented 6 years ago

Yeah. I came across that but it's not approved for use at some clients .

cbaltera commented 4 years ago

Simple usage of cucumber has been moved to https://github.com/galatea-associates/fuse-starter-etl/issues/1.

This task covers Raj's DSL request and using cucumber to test REST services. The remaining decision is to determine whether or not to use cukes-rest (vs writing our own DSL). The dev task is to either write and integrate the DSL or to integrate cukes, as appropriate.

mikegajda commented 4 years ago

Decision: try using rest-cukes and see if there are any major deficiencies. If not, use what's already been written with rest-cukes, otherwise make our own.