Karate and Rest are very different when it come to API tetsing.

API Testing Tools: REST-Assured and Karate

REST-Assured is one of the most established API testing tools in the market. It has a powerful Java-based API that leverages Hamcrest as the matcher tool. It also has a simple set of methods that allows method chaining and Pseudo-Gherkin Syntax.

Karate, on the other hand, is a Gherkin-based API testing tool. It’s ideal for quick prototyping as well as simpler testing that can be as in-depth as you want. Karate includes a simple quick start mode, integrated dashboards, and other goodies that are gaining attention from the testing community.

Let’s see an example on how they both differs when it comes to writing test automation code. Here I’m taking an example of creating a GIT repo using both karate and cucumber.

#KarateCode
Scenario: create GIT repo       
 Given url ‘https://api.github.com/user/repo’  
 And request { name: ‘MyRepo’ }
 When method post  Then status 201
 And match response ==
{ id:‘#number’, name:‘MyRepo’ }
#REST-assured
public void createGITRepo() {  
given()
.contentType(ContentType.JSON)
.body("{\"name\": \”MyRepo\"}")
.when()
.post("https://api.github.com/user/repo")
.then().statusCode(201)
.body("id",  Matchers.instanceOf(Integer.class))
.body("name", equalTo("MyRepo"));
}