SlideShare una empresa de Scribd logo
1 de 63
Descargar para leer sin conexión
TESTING LIBRARIES
FOR FUN & PROFIT
BEWARE: INCREASED PRODUCTIVITY AHEAD@IXCHELRUIZ — PRINCIPAL CONSULTANT
TRIVADIS AG
ixchelruiz
AIM
Rest APIs
Fake Servers
Fake Clients
Parameterized Tests
Spy, Mock, Stub
ixchelruiz
Open Source
ixchelruiz
ixchelruiz
REST API
ixchelruiz
WHAT? WHY? WHO? WHEN?
REpresentational State Transfer.
“Architectural style for distributed hypermedia
systems, as it has been developed to represent the
model for how the modern Web should work. REST
provides a set of architectural constraints that,
when applied as a whole, emphasizes scalability of
component interactions, generality of interfaces,
independent deployment of components, and
intermediary components to reduce interaction
latency, enforce security, and encapsulate legacy
systems”
ixchelruiz
WHAT? WHY? WHO? WHEN?
REpresentational State Transfer.
“Architectural style for distributed hypermedia
systems, as it has been developed to represent the
model for how the modern Web should work. REST
provides a set of architectural constraints that,
when applied as a whole, emphasizes scalability of
component interactions, generality of interfaces,
independent deployment of components, and
intermediary components to reduce interaction
latency, enforce security, and encapsulate legacy
systems”
ixchelruiz
WHAT? WHY? WHO? WHEN?
REpresentational State Transfer.
“Architectural style for distributed hypermedia
systems, as it has been developed to represent the
model for how the modern Web should work. REST
provides a set of architectural constraints that,
when applied as a whole, emphasizes scalability of
component interactions, generality of interfaces,
independent deployment of components, and
intermediary components to reduce interaction
latency, enforce security, and encapsulate legacy
systems”
— Roy Thomas Fielding
https://www.ics.uci.edu/~fielding/pubs/dissertation/web_arch_domain.htm
ixchelruiz
WHAT? WHO? WHY? WHEN?
REpresentational State Transfer.
“Architectural style for distributed hypermedia
systems, as it has been developed to represent the
model for how the modern Web should work. REST
provides a set of architectural constraints that,
when applied as a whole, emphasizes scalability of
component interactions, generality of interfaces,
independent deployment of components, and
intermediary components to reduce interaction
latency, enforce security, and encapsulate legacy
systems”
— Roy Thomas Fielding (2000)
https://www.ics.uci.edu/~fielding/pubs/dissertation/web_arch_domain.htm
ixchelruiz
STATE OF AFFAIRS
Heterogeneous collection of
terminals, workstations, servers
and supercomputers.
ixchelruiz
STATE OF AFFAIRS
Heterogeneous collection of
terminals, workstations, servers
and supercomputers.
ixchelruiz
STATE OF AFFAIRS
Evolution of REST APIs
(Model, Documentation,
Implementation)
ixchelruiz
OPEN API 3.0OAI/OPENAPI-SPECIFICATION
ixchelruiz
WHAT? WHY? WHO? WHEN?
“Define a standard, language-agnostic interface to
REST APIs which allows both humans and
computers to discover and understand the
capabilities of the service without access to source
code, documentation, or through network traffic
inspection. When properly defined via OpenAPI, a
consumer can understand and interact with the
remote service with a minimal amount of
implementation logic.”
ixchelruiz
WHAT? WHY? WHO? WHEN?
“Define a standard, language-agnostic interface to
REST APIs which allows both humans and
computers to discover and understand the
capabilities of the service without access to source
code, documentation, or through network traffic
inspection. When properly defined via OpenAPI, a
consumer can understand and interact with the
remote service with a minimal amount of
implementation logic.”
#vendorNeutral #portable #open #specification #technical
#metadata
ixchelruiz
WHAT? WHY? WHO? WHEN?
“Define a standard, language-agnostic interface to
REST APIs which allows both humans and
computers to discover and understand the
capabilities of the service without access to source
code, documentation, or through network traffic
inspection. When properly defined via OpenAPI, a
consumer can understand and interact with the
remote service with a minimal amount of
implementation logic.”
#vendorNeutral #portable #open #specification #technical
#metadata
— OpenApi Initiative
ixchelruiz
WHAT? WHO? WHY? WHEN?
“Define a standard, language-agnostic interface to
REST APIs which allows both humans and
computers to discover and understand the
capabilities of the service without access to source
code, documentation, or through network traffic
inspection. When properly defined via OpenAPI, a
consumer can understand and interact with the
remote service with a minimal amount of
implementation logic.”
#vendorNeutral #portable #open #specification #technical
#metadata
— OpenApi Initiative (Jul 26, 2017)
ixchelruiz
OPEN API INITIATIVE
ixchelruiz
WHAT? WHY? WHO? WHEN?
“The OpenAPI Initiative (OAI) was created by a
consortium of forward-looking industry experts
who recognize the immense value of standardizing
on how REST APIs are described. Provides an open
source, technical community, within which industry
participants may easily contribute to building a
vendor-neutral, portable and open specification for
providing technical metadata for REST APIs. The
OAI is a collaborative project under the guidance of
the The Linux Foundation”
ixchelruiz
WHAT? WHY? WHO? WHEN?
“The OpenAPI Initiative (OAI) was created by a
consortium of forward-looking industry experts
who recognize the immense value of standardizing
on how REST APIs are described. Provides an open
source, technical community, within which
industry participants may easily contribute to
building a vendor-neutral, portable and open
specification for providing technical metadata for
REST APIs. The OAI is a collaborative project under
the guidance of the The Linux Foundation”
ixchelruiz
WHAT? WHY? WHO? WHEN?
ixchelruiz
WHAT? WHY? WHO? WHEN?
2015
ixchelruiz
Tools that support OpenApi 3.0
http://openapi.tools
ixchelruiz
PROFIT
OPEN API
INITIATIVE & SPEC
ixchelruiz
OPEN API 3.0
“Define a standard, language-agnostic interface to
REST APIs which allows both humans and
computers to discover and understand the
capabilities of the service without access to source
code, documentation, or through network traffic
inspection. When properly defined via OpenAPI,
a consumer can understand and interact with the
remote service with a minimal amount of
implementation logic.”
— Open API Initiative
ixchelruiz
OPEN API 3.0
“Define a standard, language-agnostic interface to
REST APIs which allows both humans and
computers to discover and understand the
capabilities of the service without access to source
code, documentation, or through network traffic
inspection. When properly defined via OpenAPI,
a consumer can understand and interact with the
remote service with a minimal amount of
implementation logic.”
— Open API Initiative
ixchelruiz
REST API
SPEC
ixchelruiz
DEMO
ixchelruiz
https://editor.swagger.io
ixchelruiz
SWAGGER
EDITOR
ixchelruiz
https://github.com/swagger-api/swagger-editor
ixchelruiz
ixchelruiz
SWAGGER
CODEGEN
ixchelruiz
https://github.com/swagger-api/swagger-codegen
ixchelruiz
https://github.com/swagger-api/swagger-codegen/wiki/Server-stub-generator-HOWTO
ixchelruiz
WIREMOCK
ixchelruiz
http://wiremock.org
ixchelruiz
DEMO
ixchelruiz
ixchelruiz
Standalone
ixchelruiz
Configure ports
$ java -jar wiremock-standalone-2.19.0.jar -- port 9090
Record & Map
$ java -jar wiremock-standalone-2.19.0.jar --proxy-all http://
wiremock.org —record-mappings
Review the mappings
http://localhost:8080/__admin/
Replay
$ java -jar wiremock-standalone-2.19.0.jar
ixchelruiz
Adding mappings (text/plain)
$ curl --verbose --data '{
"request": { "url": "/get/this", "method": "GET" },
"response": {
"status": 200, "body": "Here it is!n",
"headers": {"Content-Type": "text/plain"}
}}' http://localhost:8080/__admin/mappings/new
Test the new mapping
$ curl http://localhost:8080/get/this
ixchelruiz
Adding mappings (json)
$ curl --verbose --data '{
"request": { "url": "/get/json", "method": "GET" },
"response": {
"status": 200,
"jsonBody": {"unconferences":["jCrete","jAlba","jTaco"]},
"headers": {"Content-Type": "application/json"}
}}' http://localhost:8080/__admin/mappings/new
Test the new mapping
$ curl http://localhost:8080/get/json
ixchelruiz
Adding patterns in URLs
$ curl --verbose --data '{
"request": {
"urlPathPattern": "/get/([a-z]*)/test", "method": "GET" },
"response": {
"status": 200,
"body": "Here it is with pattern"
}}' http://localhost:8080/__admin/mappings/new
Test the new mapping
$ curl http://localhost:8080/get/whatever/test
ixchelruiz
Using patterns is the body
$ curl --verbose --data '{
"request": { "method": "POST", "url": "/post/bodyPattern",
"bodyPatterns" : [ {
"equalToJson" : { "total_results": 4 } }] },
"response": {
"status": 200, "body": "The body pattern was matched"
}}' http://localhost:8080/__admin/mappings/new
Test the new mapping
$ curl --verbose --data '{
"total_results":4}'
http://localhost:8080/post/bodyPattern
ixchelruiz
http://wiremock.org/docs/request-matching/
ixchelruiz
Delaying responses
$curl --verbose --data '{
"request": { "method": "GET", "url": "/get/delayed" },
"response": {
"status": 200,
"fixedDelayMilliseconds": 2000
}}' http://localhost:8080/__admin/mappings/new
Test the new mapping
$ curl http://localhost:8080/get/delayed
ixchelruiz
Simulating Fault
$curl --verbose --data '{
"request": {
"method": "GET", "url": "/get/fault"},
"response": {
"fault": "MALFORMED_RESPONSE_CHUNK"
}}' http://localhost:8080/__admin/mappings/new
Test the new mapping
$ curl http://localhost:8080/get/fault
ixchelruiz
Verifying number of requests
$ curl -X POST --header 'Content-Type: application/json' 
--header 'Accept: application/json' 
-d '{"url":"/get/delayed"}' 'http://localhost:8080/__admin/
requests/count'
Admin reference
http://localhost:8080/__admin/docs/
Reset
http://localhost:8080/__admin/reset/
ixchelruiz
https://chrome.google.com/webstore/detail/wiremock-extension/ikiaofdpbmofgmlhajfnhdjelkleljbl
ixchelruiz
REST
ASSURE
ixchelruiz
http://rest-assured.io
ixchelruiz
ixchelruiz
EXAMPLES
ixchelruiz
import static io.restassured.RestAssured.given;

import static io.restassured.RestAssured.get;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.equalTo;
import org.junit.Test;
@Test
public void initial_data_is_loaded() {

given().
port(4567).
when().
get("/todos").
then().
body("todos.description", equalTo(asList(“Add Javadoc")));

}
@Test
public void formParamAreTreatedAsQueryParamsForGetRequests(){
given().
formParam("firstName", "John").
formParam("lastName", "Doe").
when().
get("/greet").
then().
body("greeting", equalTo("Greetings John Doe"));
}
ixchelruiz
import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.expect;
import static org.hamcrest.Matchers.equalTo;
import org.junit.Test;
@Test
public void newSyntaxWithCorrectStatusLineUsingStringMatching() {
expect().
statusLine("HTTP/1.1 200 OK").and().body("lotto.lottoId", equalTo(5)).
when().
get("/lotto");
}
@Test
public void requestSpecificationAllowsSpecifyingCookie() {
given().
cookie("username", “John”).then().
expect().
body(equalTo("username")).when().get("/cookie");
}
@Test
public void given_when_then_using_i18n_works() {
get(“/i18n").
then().
assertThat().body("ön", equalTo("Är ån"));
}
ixchelruiz
SPOCK
ixchelruiz
http://spockframework.org
ixchelruiz
ixchelruiz
EXAMPLES
ixchelruiz
@spock.lang.Unroll
class SampleControllerSpec extends spock.lang.Specification {
def "Invoke say hello with #input results in #output"() {
given:
SampleController controller = new SampleController()
controller.model = new SampleModel()
controller.service = Mock(SampleService) {
sayHello(input) >> output
}
when:
controller.model.input = input controller.sayHello()
then:
controller.model.output == output
where:
input << ['', 'Test']
output << ['Howdy, stranger!', 'Hello Test']
}
}
ixchelruiz
@spock.lang.Unroll
class SampleControllerSpec extends spock.lang.Specification {
def "Invoke say hello with #input results in #output"() {
given:
SampleController controller = new SampleController()
controller.model = new SampleModel()
controller.service = Mock(SampleService) {
sayHello(input) >> output
}
when:
controller.model.input = input
controller.sayHello()
then:
controller.model.output == output
where:
input | output
'' | 'Test'
'Howdy, stranger!' | 'Hello Test'
}
}
ixchelruiz
THANK YOU
FEEDBACK?

Más contenido relacionado

Similar a Testing libraries for fun & profit. Beware: Increased productivity ahead

Open Stack Cloud Services
Open Stack Cloud ServicesOpen Stack Cloud Services
Open Stack Cloud ServicesSaurabh Gupta
 
Open API (aka Swagger) - DDD by Night May 2020
Open API (aka Swagger) - DDD by Night May 2020Open API (aka Swagger) - DDD by Night May 2020
Open API (aka Swagger) - DDD by Night May 2020Pratik Khasnabis
 
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014openi_ict
 
2016 06 - design your api management strategy - axway - Api Management
2016 06 - design your api management strategy - axway - Api Management2016 06 - design your api management strategy - axway - Api Management
2016 06 - design your api management strategy - axway - Api ManagementSmartWave
 
C2 Matrix A Comparison of Command and Control Frameworks
C2 Matrix A Comparison of Command and Control FrameworksC2 Matrix A Comparison of Command and Control Frameworks
C2 Matrix A Comparison of Command and Control FrameworksJorge Orchilles
 
【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growth
【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growth【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growth
【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growthシスコシステムズ合同会社
 
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014Fenareti Lampathaki
 
Irakli Nadareishvili - O'Reilly SACon 2018, London
Irakli Nadareishvili - O'Reilly SACon 2018, LondonIrakli Nadareishvili - O'Reilly SACon 2018, London
Irakli Nadareishvili - O'Reilly SACon 2018, LondonIrakli Nadareishvili
 
How APIs are Transforming Cisco Solutions and Catalyzing an Innovation Ecosystem
How APIs are Transforming Cisco Solutions and Catalyzing an Innovation EcosystemHow APIs are Transforming Cisco Solutions and Catalyzing an Innovation Ecosystem
How APIs are Transforming Cisco Solutions and Catalyzing an Innovation EcosystemCisco DevNet
 
OSCON 2013 - The Hitchiker’s Guide to Open Source Cloud Computing
OSCON 2013 - The Hitchiker’s Guide to Open Source Cloud ComputingOSCON 2013 - The Hitchiker’s Guide to Open Source Cloud Computing
OSCON 2013 - The Hitchiker’s Guide to Open Source Cloud ComputingMark Hinkle
 
Building enterprise depth APIs with the IBM hybrid integration portfolio
Building enterprise depth APIs with the IBM hybrid integration portfolioBuilding enterprise depth APIs with the IBM hybrid integration portfolio
Building enterprise depth APIs with the IBM hybrid integration portfolioKim Clark
 
RefCard API Architecture Strategy
RefCard API Architecture StrategyRefCard API Architecture Strategy
RefCard API Architecture StrategyOCTO Technology
 
[WSO2 Summit Brazil 2018] The API-driven World
[WSO2 Summit Brazil 2018] The API-driven World[WSO2 Summit Brazil 2018] The API-driven World
[WSO2 Summit Brazil 2018] The API-driven WorldWSO2
 
Cloud Expo East 2013: Essential Open Source Software for Building the Open Cloud
Cloud Expo East 2013: Essential Open Source Software for Building the Open CloudCloud Expo East 2013: Essential Open Source Software for Building the Open Cloud
Cloud Expo East 2013: Essential Open Source Software for Building the Open CloudMark Hinkle
 
OpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaS
OpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaSOpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaS
OpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaSDaniel Krook
 
Red Hat Openshift on Microsoft Azure
Red Hat Openshift on Microsoft AzureRed Hat Openshift on Microsoft Azure
Red Hat Openshift on Microsoft AzureJohn Archer
 
Optimizing the Ops in DevOps
Optimizing the Ops in DevOpsOptimizing the Ops in DevOps
Optimizing the Ops in DevOpsGordon Haff
 
apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...
apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...
apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...apidays
 
Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016
Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016
Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016Istvan Rath
 

Similar a Testing libraries for fun & profit. Beware: Increased productivity ahead (20)

Open Stack Cloud Services
Open Stack Cloud ServicesOpen Stack Cloud Services
Open Stack Cloud Services
 
Open API (aka Swagger) - DDD by Night May 2020
Open API (aka Swagger) - DDD by Night May 2020Open API (aka Swagger) - DDD by Night May 2020
Open API (aka Swagger) - DDD by Night May 2020
 
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
 
2016 06 - design your api management strategy - axway - Api Management
2016 06 - design your api management strategy - axway - Api Management2016 06 - design your api management strategy - axway - Api Management
2016 06 - design your api management strategy - axway - Api Management
 
Fiware, the future internet
Fiware, the future internetFiware, the future internet
Fiware, the future internet
 
C2 Matrix A Comparison of Command and Control Frameworks
C2 Matrix A Comparison of Command and Control FrameworksC2 Matrix A Comparison of Command and Control Frameworks
C2 Matrix A Comparison of Command and Control Frameworks
 
【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growth
【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growth【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growth
【Cisco OpenStack Seminar 2015.10.26】 OpenStack as Strategy for future growth
 
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
OPENi perspective on APIs and Cloudlets @Athens hackathon, September 2014
 
Irakli Nadareishvili - O'Reilly SACon 2018, London
Irakli Nadareishvili - O'Reilly SACon 2018, LondonIrakli Nadareishvili - O'Reilly SACon 2018, London
Irakli Nadareishvili - O'Reilly SACon 2018, London
 
How APIs are Transforming Cisco Solutions and Catalyzing an Innovation Ecosystem
How APIs are Transforming Cisco Solutions and Catalyzing an Innovation EcosystemHow APIs are Transforming Cisco Solutions and Catalyzing an Innovation Ecosystem
How APIs are Transforming Cisco Solutions and Catalyzing an Innovation Ecosystem
 
OSCON 2013 - The Hitchiker’s Guide to Open Source Cloud Computing
OSCON 2013 - The Hitchiker’s Guide to Open Source Cloud ComputingOSCON 2013 - The Hitchiker’s Guide to Open Source Cloud Computing
OSCON 2013 - The Hitchiker’s Guide to Open Source Cloud Computing
 
Building enterprise depth APIs with the IBM hybrid integration portfolio
Building enterprise depth APIs with the IBM hybrid integration portfolioBuilding enterprise depth APIs with the IBM hybrid integration portfolio
Building enterprise depth APIs with the IBM hybrid integration portfolio
 
RefCard API Architecture Strategy
RefCard API Architecture StrategyRefCard API Architecture Strategy
RefCard API Architecture Strategy
 
[WSO2 Summit Brazil 2018] The API-driven World
[WSO2 Summit Brazil 2018] The API-driven World[WSO2 Summit Brazil 2018] The API-driven World
[WSO2 Summit Brazil 2018] The API-driven World
 
Cloud Expo East 2013: Essential Open Source Software for Building the Open Cloud
Cloud Expo East 2013: Essential Open Source Software for Building the Open CloudCloud Expo East 2013: Essential Open Source Software for Building the Open Cloud
Cloud Expo East 2013: Essential Open Source Software for Building the Open Cloud
 
OpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaS
OpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaSOpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaS
OpenStack and Cloud Foundry - Pair the leading open source IaaS and PaaS
 
Red Hat Openshift on Microsoft Azure
Red Hat Openshift on Microsoft AzureRed Hat Openshift on Microsoft Azure
Red Hat Openshift on Microsoft Azure
 
Optimizing the Ops in DevOps
Optimizing the Ops in DevOpsOptimizing the Ops in DevOps
Optimizing the Ops in DevOps
 
apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...
apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...
apidays Hong Kong - Why is API Gateway essential to business, Zhiyuan Ju, API...
 
Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016
Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016
Eclipse DemoCamp Budapest 2016 November: Best of EclipseCon Europe 2016
 

Más de Ixchel Ruiz

JUGUtrecht2023 - GithubActions
JUGUtrecht2023 - GithubActionsJUGUtrecht2023 - GithubActions
JUGUtrecht2023 - GithubActionsIxchel Ruiz
 
Failure is not an option
Failure is not an optionFailure is not an option
Failure is not an optionIxchel Ruiz
 
Failure is not an option
Failure is not an option Failure is not an option
Failure is not an option Ixchel Ruiz
 
JCConf.tw 2022 - DevOps for Java developers
JCConf.tw 2022 - DevOps for Java developersJCConf.tw 2022 - DevOps for Java developers
JCConf.tw 2022 - DevOps for Java developersIxchel Ruiz
 
All about dependencies
All about dependenciesAll about dependencies
All about dependenciesIxchel Ruiz
 
DevoxxMA_MavenPuzzlers.pdf
DevoxxMA_MavenPuzzlers.pdfDevoxxMA_MavenPuzzlers.pdf
DevoxxMA_MavenPuzzlers.pdfIxchel Ruiz
 
(De) Human Future
(De) Human Future(De) Human Future
(De) Human FutureIxchel Ruiz
 
DevoxxMA : The WHY series: Metrics
DevoxxMA : The WHY series: MetricsDevoxxMA : The WHY series: Metrics
DevoxxMA : The WHY series: MetricsIxchel Ruiz
 
Voxxed Banff 2018 : Containers & Integration tests
Voxxed Banff 2018 : Containers & Integration testsVoxxed Banff 2018 : Containers & Integration tests
Voxxed Banff 2018 : Containers & Integration testsIxchel Ruiz
 
DevoxxUK one size fits all
DevoxxUK   one size fits allDevoxxUK   one size fits all
DevoxxUK one size fits allIxchel Ruiz
 

Más de Ixchel Ruiz (10)

JUGUtrecht2023 - GithubActions
JUGUtrecht2023 - GithubActionsJUGUtrecht2023 - GithubActions
JUGUtrecht2023 - GithubActions
 
Failure is not an option
Failure is not an optionFailure is not an option
Failure is not an option
 
Failure is not an option
Failure is not an option Failure is not an option
Failure is not an option
 
JCConf.tw 2022 - DevOps for Java developers
JCConf.tw 2022 - DevOps for Java developersJCConf.tw 2022 - DevOps for Java developers
JCConf.tw 2022 - DevOps for Java developers
 
All about dependencies
All about dependenciesAll about dependencies
All about dependencies
 
DevoxxMA_MavenPuzzlers.pdf
DevoxxMA_MavenPuzzlers.pdfDevoxxMA_MavenPuzzlers.pdf
DevoxxMA_MavenPuzzlers.pdf
 
(De) Human Future
(De) Human Future(De) Human Future
(De) Human Future
 
DevoxxMA : The WHY series: Metrics
DevoxxMA : The WHY series: MetricsDevoxxMA : The WHY series: Metrics
DevoxxMA : The WHY series: Metrics
 
Voxxed Banff 2018 : Containers & Integration tests
Voxxed Banff 2018 : Containers & Integration testsVoxxed Banff 2018 : Containers & Integration tests
Voxxed Banff 2018 : Containers & Integration tests
 
DevoxxUK one size fits all
DevoxxUK   one size fits allDevoxxUK   one size fits all
DevoxxUK one size fits all
 

Último

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Testing libraries for fun & profit. Beware: Increased productivity ahead

  • 1. TESTING LIBRARIES FOR FUN & PROFIT BEWARE: INCREASED PRODUCTIVITY AHEAD@IXCHELRUIZ — PRINCIPAL CONSULTANT TRIVADIS AG
  • 2. ixchelruiz AIM Rest APIs Fake Servers Fake Clients Parameterized Tests Spy, Mock, Stub
  • 6. ixchelruiz WHAT? WHY? WHO? WHEN? REpresentational State Transfer. “Architectural style for distributed hypermedia systems, as it has been developed to represent the model for how the modern Web should work. REST provides a set of architectural constraints that, when applied as a whole, emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems”
  • 7. ixchelruiz WHAT? WHY? WHO? WHEN? REpresentational State Transfer. “Architectural style for distributed hypermedia systems, as it has been developed to represent the model for how the modern Web should work. REST provides a set of architectural constraints that, when applied as a whole, emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems”
  • 8. ixchelruiz WHAT? WHY? WHO? WHEN? REpresentational State Transfer. “Architectural style for distributed hypermedia systems, as it has been developed to represent the model for how the modern Web should work. REST provides a set of architectural constraints that, when applied as a whole, emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems” — Roy Thomas Fielding https://www.ics.uci.edu/~fielding/pubs/dissertation/web_arch_domain.htm
  • 9. ixchelruiz WHAT? WHO? WHY? WHEN? REpresentational State Transfer. “Architectural style for distributed hypermedia systems, as it has been developed to represent the model for how the modern Web should work. REST provides a set of architectural constraints that, when applied as a whole, emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems” — Roy Thomas Fielding (2000) https://www.ics.uci.edu/~fielding/pubs/dissertation/web_arch_domain.htm
  • 10. ixchelruiz STATE OF AFFAIRS Heterogeneous collection of terminals, workstations, servers and supercomputers.
  • 11. ixchelruiz STATE OF AFFAIRS Heterogeneous collection of terminals, workstations, servers and supercomputers.
  • 12. ixchelruiz STATE OF AFFAIRS Evolution of REST APIs (Model, Documentation, Implementation)
  • 14. ixchelruiz WHAT? WHY? WHO? WHEN? “Define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.”
  • 15. ixchelruiz WHAT? WHY? WHO? WHEN? “Define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.” #vendorNeutral #portable #open #specification #technical #metadata
  • 16. ixchelruiz WHAT? WHY? WHO? WHEN? “Define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.” #vendorNeutral #portable #open #specification #technical #metadata — OpenApi Initiative
  • 17. ixchelruiz WHAT? WHO? WHY? WHEN? “Define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.” #vendorNeutral #portable #open #specification #technical #metadata — OpenApi Initiative (Jul 26, 2017)
  • 19. ixchelruiz WHAT? WHY? WHO? WHEN? “The OpenAPI Initiative (OAI) was created by a consortium of forward-looking industry experts who recognize the immense value of standardizing on how REST APIs are described. Provides an open source, technical community, within which industry participants may easily contribute to building a vendor-neutral, portable and open specification for providing technical metadata for REST APIs. The OAI is a collaborative project under the guidance of the The Linux Foundation”
  • 20. ixchelruiz WHAT? WHY? WHO? WHEN? “The OpenAPI Initiative (OAI) was created by a consortium of forward-looking industry experts who recognize the immense value of standardizing on how REST APIs are described. Provides an open source, technical community, within which industry participants may easily contribute to building a vendor-neutral, portable and open specification for providing technical metadata for REST APIs. The OAI is a collaborative project under the guidance of the The Linux Foundation”
  • 23. ixchelruiz Tools that support OpenApi 3.0 http://openapi.tools
  • 25. ixchelruiz OPEN API 3.0 “Define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.” — Open API Initiative
  • 26. ixchelruiz OPEN API 3.0 “Define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.” — Open API Initiative
  • 41. ixchelruiz Configure ports $ java -jar wiremock-standalone-2.19.0.jar -- port 9090 Record & Map $ java -jar wiremock-standalone-2.19.0.jar --proxy-all http:// wiremock.org —record-mappings Review the mappings http://localhost:8080/__admin/ Replay $ java -jar wiremock-standalone-2.19.0.jar
  • 42. ixchelruiz Adding mappings (text/plain) $ curl --verbose --data '{ "request": { "url": "/get/this", "method": "GET" }, "response": { "status": 200, "body": "Here it is!n", "headers": {"Content-Type": "text/plain"} }}' http://localhost:8080/__admin/mappings/new Test the new mapping $ curl http://localhost:8080/get/this
  • 43. ixchelruiz Adding mappings (json) $ curl --verbose --data '{ "request": { "url": "/get/json", "method": "GET" }, "response": { "status": 200, "jsonBody": {"unconferences":["jCrete","jAlba","jTaco"]}, "headers": {"Content-Type": "application/json"} }}' http://localhost:8080/__admin/mappings/new Test the new mapping $ curl http://localhost:8080/get/json
  • 44. ixchelruiz Adding patterns in URLs $ curl --verbose --data '{ "request": { "urlPathPattern": "/get/([a-z]*)/test", "method": "GET" }, "response": { "status": 200, "body": "Here it is with pattern" }}' http://localhost:8080/__admin/mappings/new Test the new mapping $ curl http://localhost:8080/get/whatever/test
  • 45. ixchelruiz Using patterns is the body $ curl --verbose --data '{ "request": { "method": "POST", "url": "/post/bodyPattern", "bodyPatterns" : [ { "equalToJson" : { "total_results": 4 } }] }, "response": { "status": 200, "body": "The body pattern was matched" }}' http://localhost:8080/__admin/mappings/new Test the new mapping $ curl --verbose --data '{ "total_results":4}' http://localhost:8080/post/bodyPattern
  • 47. ixchelruiz Delaying responses $curl --verbose --data '{ "request": { "method": "GET", "url": "/get/delayed" }, "response": { "status": 200, "fixedDelayMilliseconds": 2000 }}' http://localhost:8080/__admin/mappings/new Test the new mapping $ curl http://localhost:8080/get/delayed
  • 48. ixchelruiz Simulating Fault $curl --verbose --data '{ "request": { "method": "GET", "url": "/get/fault"}, "response": { "fault": "MALFORMED_RESPONSE_CHUNK" }}' http://localhost:8080/__admin/mappings/new Test the new mapping $ curl http://localhost:8080/get/fault
  • 49. ixchelruiz Verifying number of requests $ curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"url":"/get/delayed"}' 'http://localhost:8080/__admin/ requests/count' Admin reference http://localhost:8080/__admin/docs/ Reset http://localhost:8080/__admin/reset/
  • 55. ixchelruiz import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.get; import static java.util.Arrays.asList; import static org.hamcrest.Matchers.equalTo; import org.junit.Test; @Test public void initial_data_is_loaded() {
 given(). port(4567). when(). get("/todos"). then(). body("todos.description", equalTo(asList(“Add Javadoc")));
 } @Test public void formParamAreTreatedAsQueryParamsForGetRequests(){ given(). formParam("firstName", "John"). formParam("lastName", "Doe"). when(). get("/greet"). then(). body("greeting", equalTo("Greetings John Doe")); }
  • 56. ixchelruiz import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.expect; import static org.hamcrest.Matchers.equalTo; import org.junit.Test; @Test public void newSyntaxWithCorrectStatusLineUsingStringMatching() { expect(). statusLine("HTTP/1.1 200 OK").and().body("lotto.lottoId", equalTo(5)). when(). get("/lotto"); } @Test public void requestSpecificationAllowsSpecifyingCookie() { given(). cookie("username", “John”).then(). expect(). body(equalTo("username")).when().get("/cookie"); } @Test public void given_when_then_using_i18n_works() { get(“/i18n"). then(). assertThat().body("ön", equalTo("Är ån")); }
  • 61. ixchelruiz @spock.lang.Unroll class SampleControllerSpec extends spock.lang.Specification { def "Invoke say hello with #input results in #output"() { given: SampleController controller = new SampleController() controller.model = new SampleModel() controller.service = Mock(SampleService) { sayHello(input) >> output } when: controller.model.input = input controller.sayHello() then: controller.model.output == output where: input << ['', 'Test'] output << ['Howdy, stranger!', 'Hello Test'] } }
  • 62. ixchelruiz @spock.lang.Unroll class SampleControllerSpec extends spock.lang.Specification { def "Invoke say hello with #input results in #output"() { given: SampleController controller = new SampleController() controller.model = new SampleModel() controller.service = Mock(SampleService) { sayHello(input) >> output } when: controller.model.input = input controller.sayHello() then: controller.model.output == output where: input | output '' | 'Test' 'Howdy, stranger!' | 'Hello Test' } }