SlideShare a Scribd company logo
Globalcode – Open4education
Trilha – DevTest
Karatê DSL - Testes de API de forma simples
Globalcode – Open4education
Quem somos
Globalcode – Open4education
porque automatizar?
Globalcode – Open4education
Globalcode – Open4education
Health
Check
Contrato Aceitação Funcional
Testes de API
Globalcode – Open4education
Karate
DSL para testes de api
Open Source
Autor: Peter Thomas / @ptrthomas
Versão atual: 0.9.4
Lançamento: ~ 2 anos atrás
Popularidade: +1900 +2100★ Github
Globalcode – Open4education
Karate - API’s
Karate Karate Netty Karate Gatling
API Test API Mock API Perf
Globalcode – Open4education
ok, mas como isso ajuda?
Globalcode – Open4education
Sintaxe simples
Scenario: Listar livros cadastrados
Given path 'books'
When method GET
Then status 200
And match response.data == '# []'
Globalcode – Open4education
Comandos simples
URL & PATH
* url 'http://meuservico.com/'
Given path 'books'
Globalcode – Open4education
HEADERS, PARAMS E FORM FIELDS
And header myHeader = 'valor'
And headers myHeaders = { chave: 'valor' }
> segue a mesma sintaxe para params & form fields
Comandos simples
Globalcode – Open4education
METHOD <HTTP method>
When method GET
# POST / PUT / DELETE / PATCH
Comandos simples
Globalcode – Open4education
STATUS <HTTP status>
Then status 200
# 2xx / 3xx / 4xx / 5xx
Comandos simples
Globalcode – Open4education
ASSERT AND MATCH
Then assert <expression>
Then match <expression>
Comandos simples
Globalcode – Open4education
Fuzzy matching
Globalcode – Open4education
Testes de contrato
PAYLOAD
{
"id": 1,
"title": "Book 1",
"isAvailable": true,
"publishDate": "Lorem lorem lorem.
}
KARATE SCHEMA
{
"id": "#number",
"title": "#string",
"isAvailable": "#boolean",
"publishDate": "#present",
}
Then match payload == schema
Globalcode – Open4education
Gif importando collection do
postman
Globalcode – Open4education
ok, e como eu rodo esses testes?
Globalcode – Open4education
Karate DSL - Execução (stand)
java -jar karate.jar src/features
Globalcode – Open4education
Karate DSL - Execução (gherkin plugin)
Globalcode – Open4education
Karate DSL - Execução (runner)
//outros imports que não imports nesse moments
public class ApiStatusRunner {
@Test
public void testParalell() {
}
Globalcode – Open4education
ok, e como vejo se meu teste passou?
Globalcode – Open4education
Karate Report
Globalcode – Open4education
Cucumber Report
Globalcode – Open4education
como isso funciona?
Globalcode – Open4education
Runner
(JUnit,
TestNG)
Karate Script
(Feature)
Karate DSL Architecture
Java8JRE
Karate DSL Interpreter
(Cucumber "Step Definitions")
HTTP Client
Abstraction
Apache Jersey
JS
Engine
(Nashorn) Data Functions
match, get, set
JSON XML
Globalcode – Open4education
Karate DSL - Execução paralela
//outros imports que não imports nesse moments
import com.intuit.karate.Runner;
public class ApiStatusRunner {
@Test
public void testParalell() {
Results results = Runner.parallel(getClass(), 1);
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
Quantidade
de threads.
Globalcode – Open4education
Karate DSL - Execução paralela (stand)
java -jar karate.jar --threads 5 src/features
Globalcode – Open4education
Karate DSL - Execução paralela
> java -jar karate.jar --threads 15 src/features
Threads duração em TST (seg) duração em PROD (seg)
1 81 23
5 30 13
10 26 8
15 22 6
40 cenários
Globalcode – Open4education
Karate DSL - Karate Netty
Scenario: pathMatches('/cats') &&
methodIs('post')
* def cat = request
* def id = uuid()
* set cat.id = id
* eval cats[id] = cat
* def response = cat
Scenario: pathMatches('/cats')
* def response = $cats.*
Globalcode – Open4education
Karate DSL - Karate Netty
function fn() {
var Mock =
Java.type('com.intuit.karate.netty.FeatureServer');
var file = new
java.io.File('src/test/java/mock/web/cats-mock.feature');
var server = Mock.start(file, 0, false, null);
return server.port;
}
Globalcode – Open4education
Karate DSL - Karate Netty
Background:
* def port = karate.env == 'mock' ?
read('start-mock.js')() : 8080
* url 'http://localhost:' + port + '/cats'
Scenario: create cat
Given request { name: 'Billie' }
When method post
Then status 200
And match response == { id: '#uuid', name:
'Billie' }
And def id = response.id
Globalcode – Open4education
Karate DSL - Karate Gatling
class KarateSimulation extends Simulation {
val protocol = karateProtocol()
val scn = scenario("Gatling
Test").exec(karateFeature("classpath:starwars/Dojo.feature"))
setUp(
scn.inject(rampUsers(10) over (20
seconds)).protocols(protocol)
)
}
Globalcode – Open4education
Karate DSL - Karate Gatling
Globalcode – Open4education
Karate DSL - Karate Gatling
Globalcode – Open4education
Mas então posso usar sempre?
Globalcode – Open4education
Globalcode – Open4education
Seu contexto é importante
Globalcode – Open4education
- Cenários complexos (Múltiplas requisições na mesma feature e
cálculos)
- Java->JS->Java->JS (start-mock.js)
- Não passa "praticamente" nenhuma visão de negócio (!= BDD)
Quando não usar
Globalcode – Open4education
Hands on
Globalcode – Open4education
em progresso
Karate
API
Karate
Netty
Karate
Gatling
Karate
Driver
Karate
Appium
Karate
Desktop
KarateFramework
Globalcode – Open4education
Karatê DSL - Cobertura
> https://github.com/samlucax/karate-demo-tdc#code-coverage-using-jacoco
mvn clean test -Pcoverage
Globalcode – Open4education
Karate DSL - Cobertura com Jacoco
Globalcode – Open4education
Karatê DSL
Integração Contínua - Travis
Globalcode – Open4education
Métricas - Report Portal
Globalcode – Open4education
Lembre-se: o contexto importa
Globalcode – Open4education
github.com/samlucax/karate-example
Artigo & Projeto
Globalcode – Open4education
github.com/samlucax/karate-demo-tdc
Karate Demo
Globalcode – Open4education
Obrigado!
Samuel Lucas
@samlucax
Ernesto Barbosa
@ernestosbarbosa

More Related Content

PDF
Karate - Web-Service API Testing Made Simple
VodqaBLR
 
PPTX
Karate - MoT Dallas 26-Oct-2017
Peter Thomas
 
PDF
Karate - powerful and simple framework for REST API automation testing
Roman Liubun
 
PPTX
Karate for Complex Web-Service API Testing by Peter Thomas
intuit_india
 
PPTX
Automate right start from API
Roman Liubun
 
PDF
Karate, the black belt of HTTP API testing?
Bertrand Delacretaz
 
PPTX
A Deep Dive into the W3C WebDriver Specification
Peter Thomas
 
PDF
Karma - JS Test Runner
Sebastiano Armeli
 
Karate - Web-Service API Testing Made Simple
VodqaBLR
 
Karate - MoT Dallas 26-Oct-2017
Peter Thomas
 
Karate - powerful and simple framework for REST API automation testing
Roman Liubun
 
Karate for Complex Web-Service API Testing by Peter Thomas
intuit_india
 
Automate right start from API
Roman Liubun
 
Karate, the black belt of HTTP API testing?
Bertrand Delacretaz
 
A Deep Dive into the W3C WebDriver Specification
Peter Thomas
 
Karma - JS Test Runner
Sebastiano Armeli
 

What's hot (20)

PPTX
Mock cli with Python unittest
Song Jin
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
ODP
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
PDF
Angularjs - Unit testing introduction
Nir Kaufman
 
PDF
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
Ortus Solutions, Corp
 
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
PDF
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Gavin Pickin
 
PPTX
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
PDF
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
PDF
Living With Legacy Code
Rowan Merewood
 
PPT
10reasons
Li Huan
 
PDF
Testing Legacy Rails Apps
Rabble .
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PDF
CommandBox & ForgeBox Package Management
Ortus Solutions, Corp
 
PDF
cf.Objective() 2017 - Design patterns - Brad Wood
Ortus Solutions, Corp
 
PDF
AngularJS Unit Test
Chiew Carol
 
PPTX
Legacy Dependency Kata v2.0
William Munn
 
PPTX
Legacy Code Kata v3.0
William Munn
 
PPTX
Lombok
Amit Aggarwal
 
Mock cli with Python unittest
Song Jin
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
Angularjs - Unit testing introduction
Nir Kaufman
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
Ortus Solutions, Corp
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Gavin Pickin
 
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
Living With Legacy Code
Rowan Merewood
 
10reasons
Li Huan
 
Testing Legacy Rails Apps
Rabble .
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
CommandBox & ForgeBox Package Management
Ortus Solutions, Corp
 
cf.Objective() 2017 - Design patterns - Brad Wood
Ortus Solutions, Corp
 
AngularJS Unit Test
Chiew Carol
 
Legacy Dependency Kata v2.0
William Munn
 
Legacy Code Kata v3.0
William Munn
 
Ad

Recently uploaded (20)

PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Software Development Methodologies in 2025
KodekX
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Software Development Methodologies in 2025
KodekX
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Ad

TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de API de forma simples