Karates’ journey started roughly four years ago and these four years haven’t been easy, how could they? Imagine all the time it takes to drive an open-source project all the way until it gets noticed, used, and finally, got listed on the Thought Works Technologie Radar - even if it’s not listed on the current round.
And today, after 4 years, version 1.0 is in reach. Peter Thomas already released the third candidate, and there isn’t much left.
That’s a reason for me to take a closer look at the upcoming version, and here it is, my list of the most favored features of Karate Automation Framework version 1.0.
Fell free to download the code examples from: https://github.com/peterquiel/karate-getting-started-guide/tree/master/karate-standalone-setup/src/examples/users
Support for all Java versions 8 and above
Think of the situation you want to use Karate in your Tool Stack and you know that Karate isn’t future proof. This would be a major showstopper for me if I have to decide.
GraalVM? Do I have to use another JDK to run karate now?
Not really. The
karate-core comes now with all the dependency you need - this is actually another improvement - to run it on every JDK
version 8 and above, and that includes JDK version 15 in particular. Needless to say, it’s JDK 16 ready as well!
Another idea that pops up in my mind when I hear GraalVM
is: native image
Native Image is a technology to ahead-of-time compile Java code to a standalone executable, called a native image.
These executables don’t need a JDK at all and run faster, but I ran into a few issues with creating a native image, and since this isn’t a blog post on how to create a karate native image, I didn’t dig deeper into this topic.
On the other hand, Karate starts and runs fast enough on top of a JVM and doesn’t need a performance boost necessarily.
Improved error details for match failures
match command with its
contains any operators are very powerful. The JSON schema expressions add another
level of dense expressiveness, and that confused me sometimes when I try to understand why this particular case didn’t work.
It looks like I wasn’t the only one having problems understanding why a matcher’s expression didn’t match or match.
Karate matcher,… talk to me!
The new matcher talks to you in a more detailed way to explain the
This will fail, because
2 and not
Before Karate 1.0:
With Karate 1.0:
Wow, what an improvement. Spotting mismatches in leaves can’t be easier.
HTML Templating Engine - Thymeleaf Integration
Along with Karate 1.0 release comes a Thymeleaf
Thymeleaf integration for report rendering. This is what you always wanted to generate human-readable reports.
This is a really valuable feature you want when you integrated Karate into your testing environment and you use Karate testing results as a communication medium or as a QS report.
Using templates is easy, and the integration in your test case is straightforward.
First, you create a simple HTML template file like this one:
Second, you render that template using the already known
The resulting report looks like this:
One other important thing to note about the new integrated Thymeleaf Engine is that Karate is actually dogfooding this for its own reports, as you can see from the karate-step.html template.
When Peter told me about that dogfooding the next thought that came to my mind is: “Can you configure the template karate should use?” and the answer is: “Configuration isn’t part of the current release candidate 0.9.9.RC3, but will be in 1.0.”
So, in the future, you will be able to customize the report as you like and to load your customized templates from a
jar for instance.
This enables you to share your reporting templates across teams and your company.
I could even imagine that third parties publish their own report templates to the maven repository, and you can easily take advantage of that.
Often you decide to introduce a new tool into your tech stack and you may have evaluated that tool using a comparison matrix, but you can’t think of every use case and for scaling your stack if often gets dirty.
It’s too late to step back, and it has to work.
API testing isn’t the fasted tool you have on your test workbench, and automated browser tests are even worse. While during API tests the machine mostly waits for IO and has nothing to do, browser testing becomes quite CPU intense.
Sometimes you want to test how fast a website renders on a slow machine, and you, therefore, you want to render the website with CPU reduced setup.
Distributed Testing helps you to fulfill these requirements when you want to improve test execution time. It’s not an easy setup, it adds complexity, it will increase your false-positive rates, because some of your tests might not run in parallel, but having this opportunity is better than none.
Karate 1.0 comes with Distributed Testing support, and Peter Thomas asks for your support since it’s difficult to test and debug.
I haven’t tried it. It’s like reactive programming, it’s fun to play with, but you don’t want to use it in production until you have to.
Nevertheless, it’s an important feature if karate wants to be enterprise-ready!
I don’t know how often I used the
=> operator in Karate before I learned that Karate isn’t ES6 ready.
ES6 may look like a slight improvement. I mean, you don’t write loads of JS code in Karat, do you?
But since almost every JS environment runs ES6, it would feel like Karate is falling behind without that support. If you don’t move, you fall behind.
Just a little example, that shows pretty much of the new stuff:
The improved JS failures are worth mentioning as well because in the past I have faced different situations where I changed JS code in small incremental changes to find the reason.
I removed the
new Date() in the code above and when I try to execute that, I will get this improved error message:
JS Functions for Data Driven Testing
Data-Driven test cases have been a really helpful tool for me. I used this feature often in combination with reading test data from a CSV file that karate turns automatically into a JSON.
This is a simple example that shows the expressiveness of the newly introduced ES6 support.
But is that all?
One thing that pops up in my mind that is much easier to use with this new feature is Property-Based Testing.
Property-Based Testing is an interesting approach. Unfortunately, I did not manage to make it a tool of my daily use. The simplicity - and its limitation - of imperative test cases are too strong.
I hope this feature enables others to experiment more!
Peter Thomas restructured the dependencies and now
karate-core comes with all its dependencies in one jar. This might look like an
anti-pattern if you think of modularity.
But Karate isn’t part of an enterprise application that consists of 100ths of jar files. Principles applied in that situation don’t
necessarily apply here. It’s an interpreter for your
.feature files, and a single dependency makes it easy to execute your feature file.
Simple execution is the driver of this improvement, and Peter Thomas provides a simple example of how jbang helps you.
In this Karate Java API showcase Peter Thomas demonstrates how you can execute a Karate test case using a simple command:
Releasing Version 1.0 is something special, it’s the state of your software as you imagined it when you started your journey.
The journey of Karate started ~4 years ago, and it gained a lot of attention during this period of time. Many people are using it every day and some people don’t like it at all. Some of them think, it’s BDD for people who can’t program or it’s just too different and they want to stay in their comfort zone. It’s easy to judge from the sidewalk.
So, Karate isn’t a perfect tool, but perfection won’t get you done.
I don’t like everything about Karate, and in particular, I don’t like the small little inconsistent language decisions, like the switch
So, Karate isn’t a perfect tool, but perfection won’t get you done, and done is better than perfect. I have had so many brilliant ideas and none of them were made to the public because every brilliant, perfect idea gets dirty and rusty when facing reality. Most people quit when this uniform optimism transforms into an informed pessimism and the cost of reality becomes apparent.
Peter Thomas, the major force behind karate, didn’t quit, nor did he pay too much attention to the awful voices. His consistency and discipline lead to what karate is today.
A beautiful, imperfect, and powerful tool I don’t want to miss in my toolbox.
Congratulations Karate to your first version!