api integration testing with karate-gerbenvermoen · karate enables you to script a sequence of...

18
www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate 1 MARKETOFY ULTIMATE POWERPOINT TEMPLATE API iNtegration testing with karate GERBEN VERMOEN

Upload: others

Post on 02-Apr-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�1

MARKETOFYULTIMATE POWERPOINT TEMPLATE

API iNtegration testing with karate

GERBEN VERMOEN

Page 2: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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

Page 3: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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

Page 4: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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

Page 5: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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…

Page 6: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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

Page 7: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�7

The problem with unit tests…

Page 8: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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

Page 9: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

Setting up karate�9

Page 10: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�10

First Features

Page 11: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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

Page 12: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�12deterministic testing

Page 13: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�13Reporting

Page 14: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�14reusability

Page 15: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�15test doubles

Page 16: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�16

Other Features

Page 17: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

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)

Page 18: API Integration Testing With Karate-GerbenVermoen · Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected. It

www.github.com/intuit/karate www.github.com/gvermoen/nloug-karate

�18

THANKS FOR WATCHINGSee You Next Time

@gvermoen@KarateDSL