SlideShare a Scribd company logo
1 of 39
Test the REST
Testing RESTful web services using REST Assured
An open source workshop by …
Originally created by Bas Dijkstra – bas@ontestautomation.com – http://www.testautomation.com - @_basdijkstra
What are we going to do?
_RESTful web services
_REST Assured
_Get your hands dirty
Preparation
_Install Eclipse (or any other IDE)
_Install TestNG plugin (for Eclipse)
_Install m2e (or similar for any other IDE)
_Import Maven project into IDE
_Update project (Eclipse) or similar
What are RESTful web services?
_HTTP request methods (GET, POST, PUT, …)
_URI’s
_CRUD operations on data
POST Create
GET Read
PUT Update
DELETE Delete
An example
_GET http://api.zippopotam.us/us/90210
_Result:
Usage of RESTful web services
_Mobile applications
_Internet of Things
_API Economy
Why REST (and not SOAP, for
example)?
_Support for a multitude of data formats
_JSON
_XML
_…
_Smaller overhead and therefore better
performance
Why SOAP(and not REST, for
example)?
_WS-Security
_WS-ReliableMessaging
_WS-AtomicTransaction
_Mostly used to secure banking applications
Tools for testing RESTful web
services
_Browser (using plugins like Postman for Chrome)
_Open source (SoapUI, REST Assured)
_COTS (Parasoft SOAtest, SoapUI Pro)
REST Assured
_Java library for writing tests for RESTful web
services
_Removes a lot of boilerplate code
_Integrates seamlessly with existing Java-based
testing frameworks
_JUnit, TestNG
_Selenium WebDriver
Configuring REST Assured
_Download from http://rest-assured.io
_Add as a dependency to your project
_Maven
REST Assured documentation
_Usage guide
_https://github.com/rest-assured/rest-assured/wiki/Usage
_Links to other documentation (JavaDoc, getting
started, release notes)
_http://rest-assured.io/
A sample test
REST Assured features
_Support for HTTP methods (GET, POST, PUT, …)
_Support for BDD / Gherkin (Given/When/Then)
_Use of Hamcrest matchers for checks (equalTo)
_Use of GPath for selecting elements from JSON
response
About Hamcrest matchers
_Express expectations in natural language
_Examples:
_ http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html
equalTo(X) Does the object equal X?
hasItem(“Rome”) Does the collection contain an item “Rome”?
hasSize(3) Does the size of the collection equal 3?
not(equalTo(X)) Inverts matcher equalTo()
About GPath
_GPath is a path expression language integrated
into Groovy
_REST Assured is built in Groovy
_Similar aims and scope as XPath for XML
_Documentation and examples:
_http://groovy-lang.org/processing-xml.html#_gpath
_http://groovy.jmiguel.eu/groovy.codehaus.org/GPath.html
GPath example
http://goessner.net/articles/JsonPath/
Validating technical response
data
_HTTP status code
_MIME-type of received responses
_Cookies and their value
_…
Our application under test
_Ergast F1 API
_Presents historical data of Formula 1 races,
drivers, circuits, etc.
_Data can be returned in JSON and XML format
_API documentation at http://ergast.com/mrd/
Some examples
_Data for driver Max Verstappen (in JSON):
http://ergast.com/api/f1/drivers/max_verstappen.json
_A list of circuits for the 2015 season (in JSON):
http://ergast.com/api/f1/2015/circuits.json
Demo
_API documentation
_How to use the test suite
_Executing your tests
_Reviewing test results
Get your hands dirty!
_RestAssuredExercises1
_Simple checks
_Validating individual elements
_Validating collections and items therein
_Validating technical response properties
_RestAssuredExamples contains all examples from
the presentation
Parameters in RESTful web
services
_Path parameters
_http://ergast.com/api/f1/drivers/max_verstappen.json
_http://ergast.com/api/f1/drivers/hamilton.json
_Query string parameters
_http://md5.jsontest.com/?text=testcaseOne
_http://md5.jsontest.com/?text=testcaseTwo
_There is no official standard!
Using parameters in REST Assured
_Examples for query parameters:
_ Call to http://md5.jsontest.com/?text=testcaseOne
_ Call to http://api.openweathermap.org/data/2.5/weather/?q=Kopenhagen&mode=xml
Using parameters in REST Assured
_Examples for path parameters:
_ Call to http://ergast.com/api/f1/drivers/max_verstappen.json
_ Call to http://ergast.com/api/f1/drivers/alonso/constructors/renault/seasons.json
Using parameters in REST Assured
_Iterating over a collection of parameter values:
_ Creating pairs of driver ID’s and numbers:
_ Using test data in API calls and validation of response data:
Get your hands dirty!
_RestAssuredExercises2
_Data driven tests
_Creating a test data object
_Using test data in calling the right URI
_Using test data in assertions
_RestAssuredExamples contains all examples from
the presentation
Authentication
_Securing web services
_Basic authentication (preemptive / challenged)
_OAuth(2)
_Digest / Form
Basic authentication
_Username/password sent in header for every request
OAuth(2)
_Request of authentication token based on
username and password (Basic authentication)
_Include authentication token in header of all
subsequent requests
Measuring response times
_Measuring response times for individual requests
_Setting response time thresholds
_Test fails when threshold is exceeded
_No full-fledged performance test
_First rough indication of API performance
Measuring response times
_An example:
Get your hands dirty!
_RestAssuredExercises3
_Communicating with an OAuth2-secured API
_ Requesting authentication token
_ Using authentication token in subsequent requests
_Measuring API response times
_ Execute a specific API call
_ Evaluate response time against predefined threshold
_RestAssuredExamples contains all examples from the
presentation
Sharing variables between tests
_Example: authentication tests
_Copy / paste required for OAuth2 token
_Preferably: store and retrieve for reuse!
Sharing variables between tests
_REST Assured
supports this
with extract()
Get your hands dirty!
_RestAssuredExercises4
_Try it for yourself
_Can you apply this to the Formula 1 API?
_RestAssuredExamplesParameterPassing contains
all examples from the presentation
Executing tests in CI
_REST Assured-tests are no different from other
Java (unit) tests
_Can be easily added to your CI/CD pipeline
_Part of the build process
_Demonstration (using Jenkins)
Questions
Contact
_Email: bas@ontestautomation.com
_Weblog: http://www.ontestautomation.com
_Twitter: @_basdijkstra

More Related Content

What's hot

An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API TestingSauce Labs
 
API Test Automation
API Test Automation API Test Automation
API Test Automation SQALab
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
Rest API Automation with REST Assured
Rest API Automation with REST AssuredRest API Automation with REST Assured
Rest API Automation with REST AssuredTO THE NEW Pvt. Ltd.
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.Andrey Oleynik
 
Test in Rest. API testing with the help of Rest Assured.
Test in Rest. API testing with the help of  Rest Assured.Test in Rest. API testing with the help of  Rest Assured.
Test in Rest. API testing with the help of Rest Assured.Artem Korchevyi
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API TestingBruno Pedro
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing SwaggerTony Tam
 
Automation Testing With Appium
Automation Testing With AppiumAutomation Testing With Appium
Automation Testing With AppiumKnoldus Inc.
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsQASymphony
 
API Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj RollisonAPI Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj RollisonTEST Huddle
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveExove
 
Introduction to Test Automation
Introduction to Test AutomationIntroduction to Test Automation
Introduction to Test AutomationPekka Klärck
 

What's hot (20)

An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API Testing
 
API Test Automation
API Test Automation API Test Automation
API Test Automation
 
Rest Assured
Rest AssuredRest Assured
Rest Assured
 
Testing microservices with rest assured
Testing microservices with rest assuredTesting microservices with rest assured
Testing microservices with rest assured
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
Api testing
Api testingApi testing
Api testing
 
Api Testing
Api TestingApi Testing
Api Testing
 
Rest API Automation with REST Assured
Rest API Automation with REST AssuredRest API Automation with REST Assured
Rest API Automation with REST Assured
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.
 
Test in Rest. API testing with the help of Rest Assured.
Test in Rest. API testing with the help of  Rest Assured.Test in Rest. API testing with the help of  Rest Assured.
Test in Rest. API testing with the help of Rest Assured.
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing Swagger
 
Automation Testing With Appium
Automation Testing With AppiumAutomation Testing With Appium
Automation Testing With Appium
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
 
API Testing for everyone.pptx
API Testing for everyone.pptxAPI Testing for everyone.pptx
API Testing for everyone.pptx
 
API Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj RollisonAPI Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj Rollison
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – Exove
 
Introduction to Test Automation
Introduction to Test AutomationIntroduction to Test Automation
Introduction to Test Automation
 
Cucumber & gherkin language
Cucumber & gherkin languageCucumber & gherkin language
Cucumber & gherkin language
 

Viewers also liked

Web (HTTP) request to response life cycle
Web (HTTP) request to response life cycleWeb (HTTP) request to response life cycle
Web (HTTP) request to response life cycleGopakumar Kunduveetil
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Ted Kulp
 
Telecommunication system
Telecommunication systemTelecommunication system
Telecommunication systemJamilah Abbas
 
Hacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques UsedHacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques UsedSiddharth Bhattacharya
 
Apache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya KulkarniApache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya Kulkarniwebhostingguy
 
Penetration testing
Penetration testingPenetration testing
Penetration testingAmmar WK
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedPort80 Software
 
Web Cookies
Web CookiesWeb Cookies
Web Cookiesapwebco
 
세션 하이재킹
세션 하이재킹세션 하이재킹
세션 하이재킹Yu Yongwoo
 
Hacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning TechniquesHacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning Techniquesamiable_indian
 
Basics of telecommunication and networking
Basics of telecommunication and networkingBasics of telecommunication and networking
Basics of telecommunication and networkingMilan Padariya
 

Viewers also liked (20)

Web (HTTP) request to response life cycle
Web (HTTP) request to response life cycleWeb (HTTP) request to response life cycle
Web (HTTP) request to response life cycle
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Smarty sharing-2
Smarty sharing-2Smarty sharing-2
Smarty sharing-2
 
Nmap scripting engine
Nmap scripting engineNmap scripting engine
Nmap scripting engine
 
Telecommunication system
Telecommunication systemTelecommunication system
Telecommunication system
 
Hacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques UsedHacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques Used
 
Cmsms, open source & business model
Cmsms, open source & business modelCmsms, open source & business model
Cmsms, open source & business model
 
Apache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya KulkarniApache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya Kulkarni
 
Penetration testing
Penetration testingPenetration testing
Penetration testing
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting Started
 
Web Cookies
Web CookiesWeb Cookies
Web Cookies
 
세션 하이재킹
세션 하이재킹세션 하이재킹
세션 하이재킹
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Web Server Hardening
Web Server HardeningWeb Server Hardening
Web Server Hardening
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Hacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning TechniquesHacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning Techniques
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Basics of telecommunication and networking
Basics of telecommunication and networkingBasics of telecommunication and networking
Basics of telecommunication and networking
 

Similar to Testing RESTful web services with REST Assured

Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
Automating Performance Monitoring at Microsoft
Automating Performance Monitoring at MicrosoftAutomating Performance Monitoring at Microsoft
Automating Performance Monitoring at MicrosoftThousandEyes
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanizecoreygoldberg
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Tim Burks
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsRapidValue
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol BuffersMatt O'Keefe
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...acijjournal
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnitMindfire Solutions
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocratJonathan Linowes
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesTao Xie
 
540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdfhamzadamani7
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 

Similar to Testing RESTful web services with REST Assured (20)

Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Automating Performance Monitoring at Microsoft
Automating Performance Monitoring at MicrosoftAutomating Performance Monitoring at Microsoft
Automating Performance Monitoring at Microsoft
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
 
Frisby Api automation
Frisby Api automationFrisby Api automation
Frisby Api automation
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and Challenges
 
540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf
 
selenium.ppt
selenium.pptselenium.ppt
selenium.ppt
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 

More from Bas Dijkstra

Test automation - put on the brakes so you can go fast
Test automation - put on the brakes so you can go fastTest automation - put on the brakes so you can go fast
Test automation - put on the brakes so you can go fastBas Dijkstra
 
20190919 backbase why_do_we_automate
20190919 backbase why_do_we_automate20190919 backbase why_do_we_automate
20190919 backbase why_do_we_automateBas Dijkstra
 
20190627 malmberg meetup_bdd_workshop
20190627 malmberg meetup_bdd_workshop20190627 malmberg meetup_bdd_workshop
20190627 malmberg meetup_bdd_workshopBas Dijkstra
 
Why do we automate?
Why do we automate?Why do we automate?
Why do we automate?Bas Dijkstra
 
Test automation and Agile software development
Test automation and Agile software developmentTest automation and Agile software development
Test automation and Agile software developmentBas Dijkstra
 
Who will guard the guards themselves? How to trust your automation and avoid ...
Who will guard the guards themselves? How to trust your automation and avoid ...Who will guard the guards themselves? How to trust your automation and avoid ...
Who will guard the guards themselves? How to trust your automation and avoid ...Bas Dijkstra
 
Supporting Continuous Testing with FITR test automation
Supporting Continuous Testing with FITR test automationSupporting Continuous Testing with FITR test automation
Supporting Continuous Testing with FITR test automationBas Dijkstra
 
Deploy and Destroy Complete Test Environments
Deploy and Destroy Complete Test EnvironmentsDeploy and Destroy Complete Test Environments
Deploy and Destroy Complete Test EnvironmentsBas Dijkstra
 
Slow tests in a fast delivery pipeline
Slow tests in a fast delivery pipelineSlow tests in a fast delivery pipeline
Slow tests in a fast delivery pipelineBas Dijkstra
 
Continuous Delivery Conference 2014 - Bas Dijkstra
Continuous Delivery Conference 2014 - Bas DijkstraContinuous Delivery Conference 2014 - Bas Dijkstra
Continuous Delivery Conference 2014 - Bas DijkstraBas Dijkstra
 

More from Bas Dijkstra (10)

Test automation - put on the brakes so you can go fast
Test automation - put on the brakes so you can go fastTest automation - put on the brakes so you can go fast
Test automation - put on the brakes so you can go fast
 
20190919 backbase why_do_we_automate
20190919 backbase why_do_we_automate20190919 backbase why_do_we_automate
20190919 backbase why_do_we_automate
 
20190627 malmberg meetup_bdd_workshop
20190627 malmberg meetup_bdd_workshop20190627 malmberg meetup_bdd_workshop
20190627 malmberg meetup_bdd_workshop
 
Why do we automate?
Why do we automate?Why do we automate?
Why do we automate?
 
Test automation and Agile software development
Test automation and Agile software developmentTest automation and Agile software development
Test automation and Agile software development
 
Who will guard the guards themselves? How to trust your automation and avoid ...
Who will guard the guards themselves? How to trust your automation and avoid ...Who will guard the guards themselves? How to trust your automation and avoid ...
Who will guard the guards themselves? How to trust your automation and avoid ...
 
Supporting Continuous Testing with FITR test automation
Supporting Continuous Testing with FITR test automationSupporting Continuous Testing with FITR test automation
Supporting Continuous Testing with FITR test automation
 
Deploy and Destroy Complete Test Environments
Deploy and Destroy Complete Test EnvironmentsDeploy and Destroy Complete Test Environments
Deploy and Destroy Complete Test Environments
 
Slow tests in a fast delivery pipeline
Slow tests in a fast delivery pipelineSlow tests in a fast delivery pipeline
Slow tests in a fast delivery pipeline
 
Continuous Delivery Conference 2014 - Bas Dijkstra
Continuous Delivery Conference 2014 - Bas DijkstraContinuous Delivery Conference 2014 - Bas Dijkstra
Continuous Delivery Conference 2014 - Bas Dijkstra
 

Recently uploaded

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 

Recently uploaded (20)

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 

Testing RESTful web services with REST Assured

  • 1. Test the REST Testing RESTful web services using REST Assured An open source workshop by … Originally created by Bas Dijkstra – bas@ontestautomation.com – http://www.testautomation.com - @_basdijkstra
  • 2. What are we going to do? _RESTful web services _REST Assured _Get your hands dirty
  • 3. Preparation _Install Eclipse (or any other IDE) _Install TestNG plugin (for Eclipse) _Install m2e (or similar for any other IDE) _Import Maven project into IDE _Update project (Eclipse) or similar
  • 4. What are RESTful web services? _HTTP request methods (GET, POST, PUT, …) _URI’s _CRUD operations on data POST Create GET Read PUT Update DELETE Delete
  • 6. Usage of RESTful web services _Mobile applications _Internet of Things _API Economy
  • 7. Why REST (and not SOAP, for example)? _Support for a multitude of data formats _JSON _XML _… _Smaller overhead and therefore better performance
  • 8. Why SOAP(and not REST, for example)? _WS-Security _WS-ReliableMessaging _WS-AtomicTransaction _Mostly used to secure banking applications
  • 9. Tools for testing RESTful web services _Browser (using plugins like Postman for Chrome) _Open source (SoapUI, REST Assured) _COTS (Parasoft SOAtest, SoapUI Pro)
  • 10. REST Assured _Java library for writing tests for RESTful web services _Removes a lot of boilerplate code _Integrates seamlessly with existing Java-based testing frameworks _JUnit, TestNG _Selenium WebDriver
  • 11. Configuring REST Assured _Download from http://rest-assured.io _Add as a dependency to your project _Maven
  • 12. REST Assured documentation _Usage guide _https://github.com/rest-assured/rest-assured/wiki/Usage _Links to other documentation (JavaDoc, getting started, release notes) _http://rest-assured.io/
  • 14. REST Assured features _Support for HTTP methods (GET, POST, PUT, …) _Support for BDD / Gherkin (Given/When/Then) _Use of Hamcrest matchers for checks (equalTo) _Use of GPath for selecting elements from JSON response
  • 15. About Hamcrest matchers _Express expectations in natural language _Examples: _ http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html equalTo(X) Does the object equal X? hasItem(“Rome”) Does the collection contain an item “Rome”? hasSize(3) Does the size of the collection equal 3? not(equalTo(X)) Inverts matcher equalTo()
  • 16. About GPath _GPath is a path expression language integrated into Groovy _REST Assured is built in Groovy _Similar aims and scope as XPath for XML _Documentation and examples: _http://groovy-lang.org/processing-xml.html#_gpath _http://groovy.jmiguel.eu/groovy.codehaus.org/GPath.html
  • 18. Validating technical response data _HTTP status code _MIME-type of received responses _Cookies and their value _…
  • 19. Our application under test _Ergast F1 API _Presents historical data of Formula 1 races, drivers, circuits, etc. _Data can be returned in JSON and XML format _API documentation at http://ergast.com/mrd/
  • 20. Some examples _Data for driver Max Verstappen (in JSON): http://ergast.com/api/f1/drivers/max_verstappen.json _A list of circuits for the 2015 season (in JSON): http://ergast.com/api/f1/2015/circuits.json
  • 21. Demo _API documentation _How to use the test suite _Executing your tests _Reviewing test results
  • 22. Get your hands dirty! _RestAssuredExercises1 _Simple checks _Validating individual elements _Validating collections and items therein _Validating technical response properties _RestAssuredExamples contains all examples from the presentation
  • 23. Parameters in RESTful web services _Path parameters _http://ergast.com/api/f1/drivers/max_verstappen.json _http://ergast.com/api/f1/drivers/hamilton.json _Query string parameters _http://md5.jsontest.com/?text=testcaseOne _http://md5.jsontest.com/?text=testcaseTwo _There is no official standard!
  • 24. Using parameters in REST Assured _Examples for query parameters: _ Call to http://md5.jsontest.com/?text=testcaseOne _ Call to http://api.openweathermap.org/data/2.5/weather/?q=Kopenhagen&mode=xml
  • 25. Using parameters in REST Assured _Examples for path parameters: _ Call to http://ergast.com/api/f1/drivers/max_verstappen.json _ Call to http://ergast.com/api/f1/drivers/alonso/constructors/renault/seasons.json
  • 26. Using parameters in REST Assured _Iterating over a collection of parameter values: _ Creating pairs of driver ID’s and numbers: _ Using test data in API calls and validation of response data:
  • 27. Get your hands dirty! _RestAssuredExercises2 _Data driven tests _Creating a test data object _Using test data in calling the right URI _Using test data in assertions _RestAssuredExamples contains all examples from the presentation
  • 28. Authentication _Securing web services _Basic authentication (preemptive / challenged) _OAuth(2) _Digest / Form
  • 29. Basic authentication _Username/password sent in header for every request
  • 30. OAuth(2) _Request of authentication token based on username and password (Basic authentication) _Include authentication token in header of all subsequent requests
  • 31. Measuring response times _Measuring response times for individual requests _Setting response time thresholds _Test fails when threshold is exceeded _No full-fledged performance test _First rough indication of API performance
  • 33. Get your hands dirty! _RestAssuredExercises3 _Communicating with an OAuth2-secured API _ Requesting authentication token _ Using authentication token in subsequent requests _Measuring API response times _ Execute a specific API call _ Evaluate response time against predefined threshold _RestAssuredExamples contains all examples from the presentation
  • 34. Sharing variables between tests _Example: authentication tests _Copy / paste required for OAuth2 token _Preferably: store and retrieve for reuse!
  • 35. Sharing variables between tests _REST Assured supports this with extract()
  • 36. Get your hands dirty! _RestAssuredExercises4 _Try it for yourself _Can you apply this to the Formula 1 API? _RestAssuredExamplesParameterPassing contains all examples from the presentation
  • 37. Executing tests in CI _REST Assured-tests are no different from other Java (unit) tests _Can be easily added to your CI/CD pipeline _Part of the build process _Demonstration (using Jenkins)

Editor's Notes

  1. Please replace the … with your own name. I would really like it if you left the bottom line intact though, as a way of thanking me. That’s really all I’m asking for, the rest of the workshop is yours to butcher (erm, improve).
  2. First: an introduction to RESTful web services, how they work and where they are used Then: an introduction to REST Assured, a Java library that can be used to write tests for RESTful web services But most importantly: you are going to have to do some work yourself! There’s not better way to learn than by doing.
  3. Depending on the way you deliver this workshop, this sheet can be altered or even removed. When I delivered it, I had participants bring in their own laptop and asked them to follow installation instructions. I only provided them for Eclipse and mentioned that whenever they wanted to use a different IDE, they were allowed to do so. I wanted to keep things simple and therefore did not provide installation instructions for other IDEs.
  4. Explain the concept of RESTful web services and compare it to your browser retrieving web pages, images, etc. from a web server (or sending data back to it).
  5. A simple example. You could also perform this one live to show the participants how easy it is to invoke a RESTful web service using your browser (it really is no different from accessing a regular web page since it’s all done over HTTP)
  6. Explain where RESTful web services are used. API Economy relates to software development exposing (parts of) their applications to the outside world through APIs, so that other developers can easily integrate their applications with it. For example: Google’s Gmail API, Maps API or the PayPal or LinkedIn APIs.
  7. Explain the reasons why REST is chosen over SOAP
  8. There are some cases where using SOAP instead of REST can be useful
  9. Three levels of tools, ranging from the very simple to the powerful and from the free to the commercial
  10. Explain what REST Assured is and why it was written Explain how REST Assured can easily be made part of a bigger testing framework covering everything from unit to end-to-end and user interface testing
  11. Briefly discuss the options available for installing and configuring REST Assured (this should be trivial for anybody with a bit of Java development experience)
  12. Notes on where to find additional information on REST Assured
  13. Demonstrate how easy it is to write a fully functional test on a RESTful web service with REST Assured. This is the only code you need. And it’s readable too!
  14. Using the example from the previous sheet, introduce some of the basic REST Assured features
  15. Go into a little more detail with regards to Hamcrest matchers – readable matchers for creating checks
  16. Go into a little more detail with regards to Gpath for effective selection of elements from XML and JSON responses
  17. Example – also explain the [0] needed since we’re dealing with a collection of Circuits here
  18. Explain how you can not only perform validations on response content, but also on response headers.
  19. Explain why this API was chosen (simple, lots of features, very ‘real’ data, something lots of people can relate to) Alternatively, you can always use your own API of course!
  20. Some basic examples on how to retrieve data from the API
  21. A quick demo before the participants start with the first series of exercises might be helpful to ensure they’ve understood everything so far and are ready to go.
  22. Speaks for itself, I think.
  23. Explain the difference between path and query string parameters in RESTful web services
  24. Explain how you define query string parameters to be used when calling a service in REST Assured (using params() )
  25. Explain how you define path parameters to be used when calling a service in REST Assured (using pathParam() )
  26. Explain how to create data driven tests using the TestNG @DataProvider and (path or query string) parameters
  27. Explain why web services sometimes need to be secured and introduce the different authentication options for RESTful web services
  28. Explain Basic (username / password) authentication
  29. Explain Oauth Retrieve access token by calling endpoint (mostly secured using Basic authentication) Include obtained authentication token in the header of all subsequent requests Explain that authentication token is tied to a specific user and that it has an expiration time (after which a new token needs to be requested)
  30. REST Assured can also measure very basic response times. This is in no way equal to a full-blown performance test, but it can be a rough indication for potential performance issues. For REAL validation of performance requirements, an actual performance test should be set up, using a dedicated performance test tool such as Apache JMeter
  31. Here’s an example of how to define a response time threshold and the error generated when the actual response time exceeds this threshold
  32. Refer to the exercise where you needed to manually copy and paste the OAuth authentication token. This is cumbersome, especially when you want to have your tests run unattended (which you want to ;). To be able to do so, you need a way to extract response values from a certain request (in this case the authentication token) and reuse it in subsequent tests.
  33. Explain the REST Assured extract() feature, which you can use (using GPath) to extract certain values from a response for later reuse.
  34. The final part of this workshop is used to explain how you can integrate your REST Assured API-level tests in a Continuous Integration setting. For my workshop, I have set up a local Jenkins installation and created a simple job that executed the tests. I then showed the build result and the console output in Jenkins to prove that the tests were indeed executed.
  35. Any questions?
  36. Here’s the part where you can shamelessly promote yourself (or give the participants your contact details in case they want more information or have any other questions, of course…). Feel free to replace this with your own contact details, you’re the one delivering the workshop after all!