1

I am trying to design a test framework using karate. I am facing a challenge there. Any help or pointers will be much appreciated .

Its a applications where extensive calculations are involved with complex mathematical rules. Some of the static parameters are fetched from database(MS SQL Server). Values for these parameters are expected to change every quarter of every 6 months.

How shall I construct my expected result set to be put in feature files so that I won't able to change it manually every time the value in database changes?

Best Regards,

Abhi

Abhi
  • 309
  • 1
  • 10
  • Why dont you fire a db query and get the values everytime you do that check in a feature file? here is an example for db query form one of the karate users https://medium.com/@snironr/perform-database-validations-in-karate-522d458aa313 – yek Oct 27 '20 at 12:45
  • Yes it can be tried. I'll just give an example like this I have atleast 100 different calculations :) (+ ∗)∗+ + ( −1)∗ (1−(∗+ ))∗& In this calculation CI Ratio and Factor Oprisk come from DB – Abhi Oct 27 '20 at 12:56

1 Answers1

1

Here's what I would do. First, move all "dynamic" stuff into JSON files. For example: constants.json

{
  "riskFactor": 0.5,
  "ciRatio": 2 
}

Then read this into a test:

Background:
* def constants = read('constants.json')

Then use the values in a test like this:

* def result = someCalc()
* match result = constants.riskFactor * 100 / constants.ciRatio

Now once you get that working, all you need to figure out is how to read that JSON file from a database. For that refer this: https://stackoverflow.com/a/52714248/143475

That said, I strongly recommend NOT using a database, it all sounds great in theory - but you are just going to add complexity and dependencies to your tests. Also, if you are going to rely on a "production" database, that violates some test principles, and I've seen many teams fall into that trap.

P.S. you can inject all key-value pairs in a JSON into scope as variables:

* karate.set(read('constants.json'))
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thanks Peter, I got some Idea atleast from your reply. Let's see how best Can I implement it. – Abhi Oct 28 '20 at 10:45