-1

Problem Statement :

  1. Microservices retrieves data from DB2 Database as part of Production
  2. Different Set of data feasible in Different Environment
  3. As part of it, it needs to ensure Retrieval logic is accurate
  4. java Code Converts DB2 Data into JSON structure
  5. Microservices logic doesnt control creating Database,its only limited to retrieval
  6. As part of above requirement , In memory DB (H2) is being discussed for Testing where data is loaded using DDL/DML and Expected JSON response to be generated manually as part of unit Testing

Test Validation Objective : test "Retrial Logic" so that irrespective of Environment, same values are retrieved .When Microservices is invoked, internally Test Harness URL calls to In Memory Database to retrieve Actual response

Test Automation Framework in Place :

  1. Karate Framework

Test Automation Approach:

  1. Load data into in Memory Database using DDL/DML (file) as part of Test Execution
  2. Invoke Microservice Request using karate
  3. Compare Actual Response against Expected JSON response captured in Step
  4. Delete the Database as part of Cleanup

Note - As it would be very tedious to write same Test Automation logic which helps to convert Data into DB ( In Memory ) to JSON (Expected Response), Expected JSON response to be captured as base expected response

Its Expected to have Test Automation Maintenance to Update DDL/DML or expected JSON is there is any change in actual Retrieval Logic.

Refernce for In memory DB Testing :

https://www.baeldung.com/spring-jpa-test-in-memory-database

#xyz-service-response.json is generated as part of unit testing while In memory DB is Created @TestRetrivalLogicusingInMemoryRequirnments Feature: demo reading files and using in a test

Background:

* url 'http://localhost:8080/api/sample/v1.0/'
    * header Accept = 'application/json'
    * configure logPrettyResponse = true
    * configure ssl = true 

Scenario: using json as a string Load data into In Memory Database ---->> This is expected Gherkin Statement. Need to understand how we can do in Karate

Given path 'getDerivedRules'
    And request { "pricingVerIds": [{ "AncestorVersionId": 123456123, "kidsVersionIds": [3432432,345324324] }],"executionFlow": "Cheque","PriceType": "dollarinINYIELD", "validationLevel": "Aggrement_LEVEL"}
    When  method POST 
    Then status 200 
    Then match $ == read('xyz-service-response.json')

Challenge and Query :

As karate Gherkin statement doesn't have Java Glue Code , and it has own DSL, can this be achieved using Karate or we need to stick to RESTAssured or similar Framework

Request for Help :

Any suggestion or code snippet to handle above would be helpful

Dhamo
  • 1,171
  • 3
  • 19
  • 41

1 Answers1

0

Absolutely possible, please refer this example in the demos: dogs.feature.

The point is you can easily mix any custom Java code into a Karate test. Please refer the documentation for more: https://github.com/intuit/karate#calling-java

You do NOT need the Cucumber "Glue" code and step-definitions to achieve this, and we consider all that as un-necessary overhead. You do NOT need a custom DSL. You just have to write custom Java code and invoke those methods from a Karate test. It may not look like "pure English" but it will get the job done in the simplest way possible.

For more examples of advanced Java interop that is possible, please see this example: https://twitter.com/KarateDSL/status/1128170638223364097

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248