Karate: 5 reasons why you should try it

Practical examples which show how to take full advantage of Karate test framework

Main advantages over REST Assured

  • No compilation needed: Karate test scripts are written as .feature files:
Karate simple example
REST-Assured example
  • Data Driven Tests: Karate provides this feature natively in two ways:
  1. ScenarioOutlines and Examples table:
Parametric tests with Scenario Outline
data-driven-example.feature
create-characters.feature
REST-Assured example with TestNG
  • Native environment switching: Karate provides an easy way to configure different environments for tests and more, in general, to configure system properties by using the karate-config.js file:
karate-config.js example
Command to execute tests in stage environment
  • Match full payload in one step: given a nested JSON in Karate is possible to match the full payload in one time, as shown below:
Example of matching full JSON object in one step
  • Update JSON payload/object: in Karate it is possible to manipulate JSON objects, for instance, set the value of a field using the set keyword, or remove by using the “remove” keyword:
Set example
Remove example

A practical code example

To better understand the difference between Karate and REST Assured also have a look at this project where the author of Karate, Peter Thomas rewrote the tests in Karate. The difference in the number of code lines is impressive: 431 against 67!

Conclusion

I still haven’t found the perfect tool for test automation (and maybe it doesn’t exist). I think testers have to try different tools to find which one is the most suitable each time depending on the needs. Try Karate, I think it’s worth it.

Image Credits: https://unsplash.com

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store