DEV Community

Apiumhub
Apiumhub

Posted on • Originally published at apiumhub.com on

Karate Framework: Let’s make API Tests great again

I’ve recently talked about a testing framework called Cypress. In this article I will talk about another one: a pretty simple testing framework for REST API Automation called Karate. In order to best describe it, here’s a pretty descriptive excerpt from the official source:

Karate Framework is the only open-source tool to combine API test-automation, mocks and performance-testing into a single, unified 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.

First, let’s compare Karate test with Cucumber and REST-Assured.

Karate:

Karate Test

Cucumber: + we must implement steps and POJO:

Cucumber Test

Rest-assured:

Rest Assured

Advantage of Karate: BDD in one place (compared with Cucumber + steps + business logic + POJOs). If you need complexity Karate has Javascript support for this.

For pre-conditions use, Karate proposes to use another feature files:

Karate Preconditions

Since Karate is written in Java, it has java integration.

Calling Java method from API test, e.x generate uniqueId:

Generate uniqueId

Another advantage of using Karate is its assertion capabilities:

Karate Assertion Capabilities

Schema validation. User friendly formating of response validation. Reusing json as a variable. Karate markers. DDT. Similar to Cucumber, but compared to Cucumber, where variables are static in the table, in Karate we can import a csv file with data. Can be user e.x. in boundary testing of api endpoint.

Boundary Testing Boundary Testing

Parallel execution. Running with Junit5. In the example we run all tests/feature files with tag @regression.

Parallel Execution

Reporting. Allure, Cucumber report. From the box Karate propose the report like next one:

Karate API Test

But also we can easily integrate Cucumber report or also Allure 😉

In case of Cucumber Report we can obtain something like:

Karate Framework API Test

Some other cool features of Karate Framework: Json Path, UI step-to-step debug, Integration with CI, Build-in ENV switcher, etc.

The post Karate Framework: Let’s make API Tests great again appeared first on Apiumhub.

Top comments (2)

Collapse
 
dmitryminchuk profile image
Dmitry Minchuk

I changed a company and found out that guys here are using Karate. The first intention was to try something new and I started learning this tool but soon it became absolutely clear that Karate is made not for real work. It’s just for marketing. It’s absolutely not usable in real world examples, it’s not maintainable, I would better implement automation in pure http client. I don’t recommend it – don’t waste your time!

Collapse
 
apolayo27 profile image
Apolayo27

How to pass an access token that answered the first service and use it in the header of the second service and use the access token that answered the second service in the header of the third service and the same with the fourth, fifth ...