Share this via ->

Why the heck is not everyone using Karate for their automated API testing in 2019?

Reading time: 17 minutes
Save this to read later on this site:
Why the heck is not everyone using Karate for their automated API testing in 2019?

What was API testing again?

I took an excerpt from Wikipedia (which has an fantastic section on Testing and Software development). I highlighted some parts ;)

API testing is a type of software testing that involves testing application programming interfaces (APIs) directly and as part of integration testing to determine if they meet expectations for functionality, reliability, performance, and security. Since APIs lack a GUI, API testing is performed at the message layer. API testing is now considered critical for automating testing because APIs now serve as the primary interface to application logic and because GUI tests are difficult to maintain with the short release cycles and frequent changes commonly used with Agile software development and DevOps.

API Testing is recognized as being more suitable for test automation and continuous testing (especially the automation used with Agile software development and DevOps) than GUI testing. Reasons cited include:

  • System complexity: GUI tests can't sufficiently verify functional paths and back-end APIs/services associated with multi-tier architectures. APIs are considered the most stable interface to the system under test.
  • Short release cycles with fast feedback loops: Agile and DevOps teams working with short iterations and fast feedback loops find that GUI tests require considerable rework to keep pace with frequent change. Tests at the API layer are less brittle and easier to maintain.

For these reasons, it is recommended that teams increase their level of API testing while decreasing their reliance on GUI testing. API testing is recommended for the vast majority of test automation efforts and as much edge testing as possible. GUI testing is then reserved for validating typical use cases at the system level, mobile testing, and usability testing.


What are existing API testing tools? 

While doing some research for this blog I came across this recent blog by Alice Aldaine about Top 10 API Testing Tools (Details & Updates Done for You!) it's a good read if you want to know more about other API testing tools. Obviously Karate is mentioned on her blog as well. This blog post is will continue with Karate DSL.

Karate DSLWhat is Karate DSL? 

Karate is new API testing kid on the block. I think they are around since 2017. However Karate is not getting enough attention for the splendid tool it is. So basically this is a shout-out in blog style. 

  • Karate is like Cucumber (Gherkin-style) so use the Cucumber-power (for example: tags and scenario-outline)
  • Tests are super-readable - as scenario data can be expressed in-line, in human-friendly JSONXML, Cucumber Scenario Outline tables, or a payload builder approach unique to Karate
  • Step Definitions Built-In  Yes. No extra Java code needed. Karate vs Cucumber
  • Single Layer of Code To Maintain  Yes. Only 1 layer of Karate-script (based on Gherkin). Karate vs Cucumber
  • Re-Use Feature Files (unlike Cucumber!)  YesKarate vs Cucumber
  • Dynamic Data-Driven Testing  Yes. Karate's support for calling other *.feature files allows you to use a JSON array as the data-source and you can use JSON or even CSV directly in a data-driven Scenario Outline.
  • Parallel Execution  Yes. Karate runs even Scenario-s in parallel, not just Feature-s.
  • Run 'Set-Up' Routines Only Once (unlike Cucumber background)  Yes.
  • Re-use of payload-data and user-defined functions across tests is so easy - that it becomes a natural habit for the test-developer
  • A zillion useful examples in their GitHub-project
  • It is worth pointing out that JSON is a 'first class citizen' of the syntax such that you can express payload and expected data without having to use double-quotes and without having to enclose JSON field names in quotes. There is no need to 'escape' characters like you would have had to in Java or other programming languages.

Also check the official video from Karate DSL. 

A part from their website:

Web-Services Testing Made Simple.

Karate is the only open-source tool to combine API test-automation, mocks and performance-testing into a singleunified framework. The BDD syntax popularized by Cucumber is language-neutral, and easy for even non-programmers. Besides powerful JSON & XML assertions, you can run tests in parallel for speed - which is critical for HTTP API testing.

You can easily build (or re-use) complex request payloads, and dynamically construct more requests from response data. The payload and schema validation engine can perform a 'smart compare' (deep-equals) of two JSON or XML documents, and you can even ignore dynamic values where needed.

Test execution and report generation feels like any standard Java project. But there's also a stand-alone executable for teams not comfortable with Java. Just write tests in a simplereadable syntax - carefully designed for HTTP, JSON, GraphQL and XML.

Karate was based on Cucumber-JVM until version 0.8.0 but the parser and engine were re-written from scratch in 0.9.0 onwards. So we use the same Gherkin syntax - but the similarity ends there.


Comments or Questions?

Want to read more about Karate DSL or shall I make a little tutorial on how to start with Karate DSL and test a real API? Let me know in the comment section below this page.

About the author:

Richard Duinmaijer

Currently there are no comments, so be the first!