API Testing Tutorial

What is API?

API (Full form Application Programming Interface) enables communication and data exchange between two separate software systems. 

A software system implementing an API contains functions/sub-routines which can be executed by another software system.

It comprises of a set of functions that can be accessed and executed by another software system.  Thus, it serves as an interface between different software systems and establishes their interaction and data exchange.

Real life Example of API:
1> Ordering food on restaurant 
2> Login to 3rd Party App using Google or Facebook Login
3> Slack Notification 


What is Web Service?

A Web Service is a service accessed via Web. Web Service is a way to publish your application over web and enable other applications to access functions defined by your web service.




Difference Between API and Web Services




Benefits of API

Benefits of API : API testing is the only way to provide truly secure, reliable and scalable connections between platforms. Testing provides these benefits.

1. Access to application without user interface
2. Protection from malicious code and breakage
3. Time Efficiency vs. functional and validation testing
4. Cost Effective / Reduces Testing Cost
5. Technology Independent

What is API Testing?


  • API testing is a software testing type that validates Application Programming Interfaces (APIs). 
  • The purpose of API Testing is to check the functionality, reliability, performance, and security of the programming interfaces. In API Testing, instead of using standard user inputs(keyboard) and outputs, you use software to send calls to the API, get output, and note down the system's response. 
  • API tests are very different from GUI Tests and won't concentrate on the look and feel of an application. 
  • It mainly concentrates on the business logic layer of the software architecture.

API Testing vs Unit Testing




Types of Output of API

Any type of data
If we are return any value to the API like submitting input values and getting output value

Status (say Pass or Fail)
If any thing goes pass or fail like value or label or message display or match value assert. Lock, Unlock, Delete status as well.

Call another API function
First API function can be used for deleting a specified record in the table and this function, in turn, calls another function to REFRESH the database.

Test Cases for API Testing

Return value based on input condition: It is relatively easy to test, as input can be defined and results can be authenticated

Does not return anything: When there is no return value, a behavior of API on the system to be checked

Trigger some other API/event/interrupt: If an output of an API triggers some event or interrupt, then those events and interrupt listeners should be tracked

Update data structure: Updating data structure will have some outcome or effect on the system, and that should be authenticated

Modify certain resources: If API call modifies some resources then it should be validated by accessing respective resources

Type of APIs

REST : (REpresentational State Transfer)

REST is an architectural style that uses simple HTTP calls for inter-machine communication. REST does not contain an additional messaging layer and focuses on design rules for creating stateless services. 

A client can access the resource using the unique URI and a representation of the resource is returned. With each new resource representation, the client is said to transfer state. 

While accessing RESTful resources with HTTP protocol, the URL of the resource serves as the resource identifier and GET, PUT, DELETE, POST and HEAD are the standard HTTP operations to be performed on that resource

SOAP : (Simple Object Access Protocol)

SOAP relies heavily on XML, and together with schema, defines a very strongly typed messaging framework. Every operation the service provides is explicitly defined, along with the XML structure of the request and response for that operation. 

Each input parameter is similarly defined and bound to a type: for example, an integer, a string, or some other complex object. All of this is codified in the WSDL – Web Service Description (or Definition, in later versions) Language. The WSDL is often explained as a contract between the provider and the consumer of the service. 

Difference Between SOAP & REST




Best Practices 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
  • Avoid "test chaining" in your development
  • Special care must be taken while handling one-time call functions like - Delete, Close Window, etc...
  • Call sequencing should be performed and well planned
  • To ensure complete test coverage, create test cases for all possible input combinations of the API.

Types of Bugs that API testing detects


  • Fails to handle error conditions gracefully
  • Unused flags
  • Missing or duplicate functionality
  • Reliability Issues. Difficulty in connecting and getting a response from API.
  • Security Issues
  • Multi-threading issues
  • Performance Issues. API response time is very high
  • Improper errors/warning to a caller
  • Incorrect handling of valid argument values
  • Response Data is not structured correctly (JSON or XML)

Challenges in API Testing


  • Main challenges in Web API testing is Parameter Combination, Parameter Selection, and Call Sequencing
  • There is no GUI available to test the application which makes difficult to give input values
  • Validating and Verifying the output in a different system is little difficult for testers
  • Parameters selection and categorization is required to be known to the testers
  • Exception handling function needs to be tested
  • Coding knowledge is necessary for testers

API Testing Tools




Manual API Testing Using POSTMAN

Automate API Testing Using Rest-Assured


API Testing Interview Question Answers

21 comments:

  1. Loved it ..
    I m mca n felt back in my college books
    D blog is efficient enough for a computer guy to grasp in an hour

    ReplyDelete
    Replies
    1. Thank You very Much !!!

      If you want One to One or Batch Training then also let us know.

      Delete
  2. Explaination is clear and detailed
    Very easy to understand
    Thankyou

    ReplyDelete
    Replies
    1. Thank You very Much !!!

      If you want One to One or Batch Training then also let us know.

      Delete
  3. Thats very great experience mine I wish I would learn API testing awsume

    ReplyDelete
    Replies
    1. Thank You very Much !!!

      If you want One to One or Batch Training then also let us know.

      Delete
    2. Follow My Blog Please by Clicking Follow button on right side panel.

      Delete
  4. Replies
    1. Thank You very Much !!!

      If you want One to One or Batch Training then also let us know.

      Follow My Blog Please by Clicking Follow button on right side panel.

      Delete
  5. Follow My Blog Please by Clicking Follow button on right side panel.

    ReplyDelete
  6. Replies
    1. Thank You very Much !!!

      If you want One to One or Batch Training then also let us know.

      Follow My Blog Please by Clicking Follow button on right side panel.

      Delete
  7. Automate API Testing Using Rest-Assured - Link is not working

    API Tutorial looks fine and short. Thanks

    ReplyDelete
    Replies
    1. Thank You for Feedback...!!

      I am preparing and uploading tutorial by myself.

      It may take time to get all topics.

      Follow blog and you will get update on new blog post.

      Thanks

      Delete
  8. Replies
    1. Thank You for Feedback...!!

      I am preparing and uploading tutorial by myself.

      It may take time to get all topics.

      Follow blog and you will get update on new blog post.

      Thanks

      Delete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Thank You for Feedback...!!

    I am preparing and uploading tutorial by myself.

    It may take time to get all topics.

    Follow blog and you will get update on new blog post.

    Thanks

    ReplyDelete