☰ See All Chapters |
Karate Tutorial - REST web service testing
This tutorial is an introduction to REST web service Testing using Karate Framework. Nowadays It has become common term calling REST web service as REST API, hence we can say Karate is used to test REST API. Karate framework is built on top of the popular Cucumber framework and using Gherkin Language. If you don’t possess knowledge of cucumber and gherkin, we suggest you understand and learn gherkin language before starting Karate. Please go through our Cucumber tutorial and Gherkin Tutorial before you start reading Karate framework.
Karate framework can be used by anyone and test cases can be read and written very easily. Karate framework uses is a gherkin which is ubiquitous language and understood by everyone involved in the project. Customers can specify expectations for the web services response easy and fast, offering a custom domain-specific language. By reading the test cases any one can visualize the system before it has been built. Anyone on the team can read a test case and reply their understanding of what the system should do, and it may well spark their imagination into thinking of other scenarios that you’ll need to consider too.
By writing test cases customer expresses how the system should behave after its complete development. This process of test-driven development is called as behaviour driven development. Behaviour Driven Development (BDD) builds upon Test Driven Development (TDD) by changing the test cases to expected behaviours.
Below is a simple syntax of karate acceptance test:
Feature: Testing sample service
Scenario: Testing sample service for success response
Given url 'https://localhost:8080/test/hello'
When method GET
Then status 200
Features of Karate
You don't need to write extra "glue" code or Java step definitions for gherkin steps. If you are using Java with maven, then you just need to use Karate dependencies in your pom.xml.
Test Script files (feature files) are plain text files doesn’t require any compilation steps.
Can cover multiple scenarios using single script (feature) file.
Scripts are re-usable that may be called from other scripts and feature files.
Native’ JSON and XML support including JsonPath and XPath expressions.
Embedded JavaScript engine that allows you to build a library of re-usable functions that suit your specific environment or organization.
Built-in support for switching configuration across different environments (e.g. dev, QA, pre-prod)
Support for data-driven tests and being able to tag or group tests is built-in, no need to rely on an external framework
Native support for reading YAML and even CSV files - and you can use them for data-driven tests.
Multi-threaded parallel execution, which is a huge time-saver, especially for integration and end-to-end tests.
Many other features are listed on the GitHub project. And below is the complete Karate Index which you can refer for more details.
All Chapters