Motivation
With Microservices architecture, comes along a plethora of challenges that need to be dealt with - and most of these challenges can be resolved with well established patterns & implementations - for ex Spring Cloud provides concrete implementations along the lines of api gateway, service discoveries , distributed tracings, externalized and centralized configuration server and the list goes on. Having said that, one of the bigger challenges I experienced is testing a distributed system[ not simply testing an individual service] as a whole. This system has many moving parts to it - there are distributed dependent services / UI's / network latencies / data inconsistencies etc.
Now, with 'shift left' being the norm - the idea is to provide faster feedbacks -> which results in faster resolutions -> which leads to better system, way earlier in development process [ vs Traditional Software Developments ].
The goal of this blog is to present Karate DSL as a possible solution for testing such a system. Overall, Karate has much much more to offer and I will encourage you to explore more.
Enter Karate DSL
In my past life I was yearning for an all encompassing automated testing framework that is:
- extension-able i.e. allow to do more with what is abstracted.
- pluggable / modular i.e. add / remove functionalities as needed.
- programming language agnostic [ as much as possible ] for wider reach among different stakeholders.
- highly observable with reporting and logging capabilities.
- ease of testing API's and UI all at the sametime. - I want to call an API to get auth token and use that token to invoke other services or UI or a combination of both.
- should be simple to learn and intuitive to use.
Behold, came the Octoberfest 2020 and I stumbled upon an amazing framework called Karate DSL. I was able to contribute, as well learn more about this awesome tool at the same time.
What is Karate DSL
Peter Thomas is the lead developer, as well main maintainer for this tool.
Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework. The BDD syntax popularized by Cucumber is language-neutral, and easy for even non-programmers. Powerful JSON & XML assertions are built-in, and you can run tests in parallel for speed.
Hands-On
Lets say, you have an API that allows to do CRUD operations on Posts. Now, look at this feature file - isn't it very intuitive as to what is going on in here? -
With this you have a simple test suite with different scenarios, and you are validating different operations on a API - all written in Gherkin Syntax. And there is nothing else to write or code - except including Karate libs.
Writing this test suite requires a very basic knowledge and anyone in your team - a developer, a tester, a BA, product owner etc. can write these and be glued with the expected behavior of the system. Include this in build pipeline or run on a schedule to measure the performance of the system - as you wish.
Now, let us look at the test report:
This is a very detailed and thorough report - you can see the timestamps and individual step logs:
You can seamlessly invoke rest apis and web UI calls in your test suite and exchange headers and cookies among those calls:
source
You can even perform accessibility testing simply as following -
and your output report looks like this:
There are many more goodies provided by this framework - docker testing support / performance testing / UI testing / test report creations etc just to name a few.
The framework has observed some amazing attraction in recent times [ see github stars ], has amazing community support via slack / stackoverflow / github and is something that should be seriously considered by architects / developers / QA alike. Cheers!
Feel free to leave any feedback.
Top comments (0)