DEV Community

loading...

Discussion on: 10 Essential Testing Frameworks & Libraries for Java Programmers

Collapse
sixman9 profile image
Richard Joseph

From what little I've seen, the executable Cumcumber/Gherkin style API testing specifications of the Karate testing framework (by Intuit, of 'Quickbooks' fame) look amazing, actually. Quoting them:

If you are familiar with Cucumber / Gherkin, the big difference here is that you don’t need to write extra “glue” code or Java “step definitions” !

The idea is, you use a VERY extended Gherkin syntax (Given-When-Then) specification definition to avoid having to write test code (although Karate does integrate with JUnit, so as to be runnable from an IDE etc.). This means that non-programmers and product owners can concretely define JSON/XML-based payloads, specify endpoint URL's, HTTP verbs and write test validation matchers, again interrogating JSON/XML/etc. return types, all from the specification script, thus:

Feature: simple example of a karate test => https://github.com/intuit/karate/blob/master/karate-netty/src/test/java/com/intuit/karate/mock/hello-world.feature

Background:
# to test that expressions also work for the method keyword
* def postMethod = 'post'
* def getMethod = 'get'

Scenario: create and retrieve a cat

Given url mockServerUrl + 'cats'
And request { name: 'Billie' }
When method postMethod
Then status 201
And match response == { id: '#ignore', name: 'Billie' }
# And assert responseTime < 1000

Given path response.id
When method getMethod
Then status 200