api integration testing with karate-gerbenvermoen · karate enables you to script a sequence of...
TRANSCRIPT
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�1
MARKETOFYULTIMATE POWERPOINT TEMPLATE
API iNtegration testing with karate
GERBEN VERMOEN
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�2
agenda
There is so much more…
Other featuresReusing features and JavaScript functions
ReusabilityAdd Cucumber reporting,
integrate Karate in CI build
ReportingRun Karate against clean
environments, parallel execution
Deterministic Testing
Karate Hello World (and a little more)
First FeaturesBuilding a demo REST
API with Spring Boot and Kotlin in 5 minutes…
Demo REST API
Karate on the other side of the fence
Test Doubles
Minimal Karate setup
Setting up KarateWhat is API Integration testing, why, and how to
do it.
Integration TestingWhat you need to code
along during the presentation
Coding Prerequisites
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�3
Java (8 or higher)1
Maven (3 or higher)2
GIT (pull from github.com/gvermoen/nloug-karate)4
An IDE with Cucumber support (optional)5
Coding prerequisites
MongoDB (3 or higher)3
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�4
Contract that defines request-response messaging over HTTP.API = SET OF DEFINED FUNCTIONS
01
The webservice could consist of many small or large components, including databases and external API’s.
IMPLEMENTED BY MULTIPLE COMPONENTS02
WHERE TO START TESTING?04
End-user applications, mobile apps, other API’s.CONSUMED BY MULTIPLE CLIENTS
03
REST / SOAP API
REST / SOAP API
DB API
ApplicationAPI
End-to-end tests
Unit tests
Integration Tests API Integration Tests
Web Service
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�5
LACK OF UNIT AND INTEGRATION TESTS01
TESTING EVERY DETAIL AS END-USER02
E2E tests usually run against non-isolated Acceptance environments and need to go through login and navigation before the test can be executed
E2E TESTS ARE BRITTLE AND TIME CONSUMING04
TEST ALL CLIENTS03
testing Anti pattern
Every supported browser and version, each app, on different devices.
Because testing always comes at the end of the line, right?
Because manual testing is all you got when you gotta go live…
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�6
If you want quality and continuous deliveryTEST AT THE LOWEST LEVEL POSSIBLE
01
Not everything can be unit tested, and integration tests are hard to write, or so it seems……….
WRITE INTEGRATION TESTS WHERE NEEDED02
Testing just below the surface of the UI of your application. SUBCUTANEOUS TESTING (MARTIN FOWLER)
04
Usually the consumer practices a different discipline and it will take more time to solve a bug. Martin Fowler: “subcutaneous testing”
VALIDATE YOUR CONTRACT WORKS03
Testing Best practice
https://martinfowler.com/bliki/TestPyramid.html
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�7
The problem with unit tests…
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�8
Null safety, less boilerplate codeKotlin
Zero configurationMongoDB
Because its good to have something familiar, isn’t it?Oracle HR schema
start.spring.ioSpring Boot 5
building a demo rest api
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
Setting up karate�9
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�10
First Features
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�11
Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It makes it really easy to build complex request payloads, traverse data within the responses, and chain data from responses into the next request. Karate's payload validation engine can perform a 'smart compare' of two JSON or XML documents without being affected by white-space or the order in which data-elements actually appear, and you can opt to ignore fields that you choose.
Since Karate is built on top of Cucumber-JVM, you can run tests and generate reports like any standard Java project. But instead of Java - you write tests in a language designed to make dealing with HTTP, JSON or XML - simple.
Scripts are plain text files, crucial for version control
Scripts are descriptive and readable, no Java knowledge required
‘native’ support for JSON and XML, including JsonPath and XPath expressions
Based on Cucumber, but no need to implement step definitions
webservices testing made simple
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�12deterministic testing
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�13Reporting
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�14reusability
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�15test doubles
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�16
Other Features
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�17
ANY QUESTIONS?The more understanding you have about Karate, the less
you need to change or modify it.
– Tsuguo Sakumoto(former World Karate Champion and master of Ryuei-ryu Karate)
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate
�18
THANKS FOR WATCHINGSee You Next Time
@gvermoen@KarateDSL