SlideShare ist ein Scribd-Unternehmen logo
1 von 18
REST API TEST
By Anil Upadhyay
Test Case Creation
• Understanding the functionality of the API program and
clearly define the scope of the program
• Apply testing techniques such as equivalence classes,
boundary value analysis, and error guessing and write test
cases for the API
• Input Parameters for the API need to be planned and
defined appropriately
• Execute the test cases and compare expected and actual
results.
Basic Practice of API Testing
• Test cases should be grouped by test category
• On top of each test, you should include the declarations of the APIs being
called.
• Parameters selection should be explicitly mentioned in the test case itself
• Prioritize API function calls so that it will be easy for testers to test
• Each test case should be as self-contained and independent from
dependencies as possible
• Call sequencing should be performed and well planned
• To ensure complete test coverage, create test cases for all possible input
combinations of the API.
Automated Testing of APIs
using Java
• Plain Old Java Object (POJO)
• Serialisation & Deserialisation
• Rest-assured
• Any Java Assert Library
POJO
• Plain Old Java Object (POJO): Pojo in Java stands for Plain Old Java Object and they are
used for increasing the readability and re-usability of a program. They are normal java
objects, unbounded by special restrictions, other than the ones forced by the Java
Language Specification.
• In simpler terms, Pojo is defined as a pure data structure, containing the getter and setter
fields. It has the ability to override certain methods from Object or an interface such as
Serializable.
• A POJO must not :
• Extend pre-specified classes: Ex- public class Test extends javax.servlet.http.HttpServlet is
not considered to be a POJO class.
• Contain pre-specified annotations: Ex- @javax.persistence.Entity public class Test{..} is not
a pojo class.
• Implement prespecified interfaces: Ex- public class Test implements javax.ejb.EntityBean {
… } is not considered to be a POJO class.
Serialisation &
Deserialisation
• Serialisation is a mechanism of converting the state of an object into a byte stream. Deserialisation is the reverse process
where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
HTTP METHODS
• HTTP defines a set of request methods to indicate the
desired action to be performed for a given resource.
Although they can also be nouns, these request methods
are sometimes referred as HTTP verbs. Each of them
implements a different semantic, but some common
features are shared by a group of them: e.g. a request
method can be safe, idempotent, or cacheable.
• GET : The GET method requests a representation of the
specified resource. Requests using GET should only
retrieve data.
HTTP METHODS
• POST: The POST method is used to submit an entity to
the specified resource, often causing a change in state or
side effects on the server.
• PUT: The PUT method replaces all current
representations of the target resource with the request
payload.
• DELETE: The DELETE method deletes the specified
resource.
• PATCH: The PATCH method is used to apply partial
modifications to a resource.
HTTP HEADERS
• HTTP headers let the client and the server pass additional
information with an HTTP request or response. An HTTP
header consists of its case-insensitive name followed by a
colon (:), then by its value. Whitespace before the value is
ignored.
• Headers can be grouped according to their contexts:
• General headers apply to both requests and responses, but
with no relation to the data transmitted in the body.
• Request headers contain more information about the resource
to be fetched, or about the client requesting the resource.
HTTP HEADERS
• Response headers hold additional information about the
response, like its location or about the server providing it.
• Entity headers contain information about the body of the
resource, like its content length or MIME type.
IMPORTANT
HEADERS
• Authorization
• Contains the credentials to authenticate a user-agent with a
server.
• Connection
• Controls whether the network connection stays open after the
current transaction finishes.
• Keep-Alive
• Controls how long a persistent connection should stay open.
IMPORTANT
HEADERS
• Accept
• Informs the server about the types of data that can be sent back.
• Accept-Language
• Informs the server about the human language the server is expected to send back. This is a
hint and is not necessarily under the full control of the user: the server should always pay
attention not to override an explicit user choice (like selecting a language from a dropdown)
• Content-Length
• The size of the resource, in decimal number of bytes.
• Content-Type
• Indicates the media type of the resource.
• https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
The GET Method
• GET is used to request data from a specified resource.
• GET is one of the most common HTTP methods.
• GET requests can be cached
• GET requests remain in the browser history
• GET requests can be bookmarked
• GET requests should never be used when dealing with sensitive data
• GET requests have length restrictions
• GET requests are only used to request data (not modify)
The GET Method
Syntax
GET /index.html
The POST Method
• The HTTP POST method sends data to the server. The type of the
body of the request is indicated by the Content-Type header.
• The difference between PUT and POST is that PUT is idempotent:
calling it once or several times successively has the same effect
(that is no side effect), where successive identical POST may have
additional effects, like passing an order several times.POST
requests are never cached
• POST requests do not remain in the browser history
• POST requests cannot be bookmarked
• POST requests have no restrictions on data length
The POST Method
POST /test HTTP/1.1
Host: foo.example
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
field1=value1&field2=value2
The PUT Method
• The HTTP PUT request method creates a new resource or replaces a representation of the target
resource with the request payload.
• The difference between PUT and POST is that PUT is idempotent: calling it once or several times
successively has the same effect (that is no side effect), where successive identical POST may
have additional effects, like passing an order several times.
The DELETE Method
• The HTTP DELETE request method deletes the specified
resource.

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Api Testing
Api TestingApi Testing
Api Testing
 
Test Design and Automation for REST API
Test Design and Automation for REST APITest Design and Automation for REST API
Test Design and Automation for REST API
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Api testing
Api testingApi testing
Api testing
 
POSTMAN.pptx
POSTMAN.pptxPOSTMAN.pptx
POSTMAN.pptx
 
Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
 
API Test Automation
API Test Automation API Test Automation
API Test Automation
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
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.
 
Api Testing.pdf
Api Testing.pdfApi Testing.pdf
Api Testing.pdf
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Rest assured
Rest assuredRest assured
Rest assured
 
Api testing
Api testingApi testing
Api testing
 
An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API Testing
 
API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0API Docs with OpenAPI 3.0
API Docs with OpenAPI 3.0
 
Postman: An Introduction for Testers
Postman: An Introduction for TestersPostman: An Introduction for Testers
Postman: An Introduction for Testers
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Rest api-basic
Rest api-basicRest api-basic
Rest api-basic
 

Ähnlich wie Rest API Testing

REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
Jeelani Shaik
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service Design
Lorna Mitchell
 

Ähnlich wie Rest API Testing (20)

Rest APIs Training
Rest APIs TrainingRest APIs Training
Rest APIs Training
 
Rest WebAPI with OData
Rest WebAPI with ODataRest WebAPI with OData
Rest WebAPI with OData
 
Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.
Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.
Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet1.ppt
Servlet1.pptServlet1.ppt
Servlet1.ppt
 
Api security-testing
Api security-testingApi security-testing
Api security-testing
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service Design
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan UllahOverview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
 
Ch 3: Web Application Technologies
Ch 3: Web Application TechnologiesCh 3: Web Application Technologies
Ch 3: Web Application Technologies
 
CNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application TechnologiesCNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application Technologies
 
RESTful Services
RESTful ServicesRESTful Services
RESTful Services
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application Technologies
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Rest API Testing

  • 1. REST API TEST By Anil Upadhyay
  • 2. Test Case Creation • Understanding the functionality of the API program and clearly define the scope of the program • Apply testing techniques such as equivalence classes, boundary value analysis, and error guessing and write test cases for the API • Input Parameters for the API need to be planned and defined appropriately • Execute the test cases and compare expected and actual results.
  • 3. Basic Practice of API Testing • Test cases should be grouped by test category • On top of each test, you should include the declarations of the APIs being called. • Parameters selection should be explicitly mentioned in the test case itself • Prioritize API function calls so that it will be easy for testers to test • Each test case should be as self-contained and independent from dependencies as possible • Call sequencing should be performed and well planned • To ensure complete test coverage, create test cases for all possible input combinations of the API.
  • 4. Automated Testing of APIs using Java • Plain Old Java Object (POJO) • Serialisation & Deserialisation • Rest-assured • Any Java Assert Library
  • 5. POJO • Plain Old Java Object (POJO): Pojo in Java stands for Plain Old Java Object and they are used for increasing the readability and re-usability of a program. They are normal java objects, unbounded by special restrictions, other than the ones forced by the Java Language Specification. • In simpler terms, Pojo is defined as a pure data structure, containing the getter and setter fields. It has the ability to override certain methods from Object or an interface such as Serializable. • A POJO must not : • Extend pre-specified classes: Ex- public class Test extends javax.servlet.http.HttpServlet is not considered to be a POJO class. • Contain pre-specified annotations: Ex- @javax.persistence.Entity public class Test{..} is not a pojo class. • Implement prespecified interfaces: Ex- public class Test implements javax.ejb.EntityBean { … } is not considered to be a POJO class.
  • 6. Serialisation & Deserialisation • Serialisation is a mechanism of converting the state of an object into a byte stream. Deserialisation is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
  • 7. HTTP METHODS • HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. Although they can also be nouns, these request methods are sometimes referred as HTTP verbs. Each of them implements a different semantic, but some common features are shared by a group of them: e.g. a request method can be safe, idempotent, or cacheable. • GET : The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
  • 8. HTTP METHODS • POST: The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server. • PUT: The PUT method replaces all current representations of the target resource with the request payload. • DELETE: The DELETE method deletes the specified resource. • PATCH: The PATCH method is used to apply partial modifications to a resource.
  • 9. HTTP HEADERS • HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value. Whitespace before the value is ignored. • Headers can be grouped according to their contexts: • General headers apply to both requests and responses, but with no relation to the data transmitted in the body. • Request headers contain more information about the resource to be fetched, or about the client requesting the resource.
  • 10. HTTP HEADERS • Response headers hold additional information about the response, like its location or about the server providing it. • Entity headers contain information about the body of the resource, like its content length or MIME type.
  • 11. IMPORTANT HEADERS • Authorization • Contains the credentials to authenticate a user-agent with a server. • Connection • Controls whether the network connection stays open after the current transaction finishes. • Keep-Alive • Controls how long a persistent connection should stay open.
  • 12. IMPORTANT HEADERS • Accept • Informs the server about the types of data that can be sent back. • Accept-Language • Informs the server about the human language the server is expected to send back. This is a hint and is not necessarily under the full control of the user: the server should always pay attention not to override an explicit user choice (like selecting a language from a dropdown) • Content-Length • The size of the resource, in decimal number of bytes. • Content-Type • Indicates the media type of the resource. • https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
  • 13. The GET Method • GET is used to request data from a specified resource. • GET is one of the most common HTTP methods. • GET requests can be cached • GET requests remain in the browser history • GET requests can be bookmarked • GET requests should never be used when dealing with sensitive data • GET requests have length restrictions • GET requests are only used to request data (not modify)
  • 15. The POST Method • The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header. • The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.POST requests are never cached • POST requests do not remain in the browser history • POST requests cannot be bookmarked • POST requests have no restrictions on data length
  • 16. The POST Method POST /test HTTP/1.1 Host: foo.example Content-Type: application/x-www-form-urlencoded Content-Length: 27 field1=value1&field2=value2
  • 17. The PUT Method • The HTTP PUT request method creates a new resource or replaces a representation of the target resource with the request payload. • The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.
  • 18. The DELETE Method • The HTTP DELETE request method deletes the specified resource.