Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design...

58
W4 API Testing Wednesday, October 23rd, 2019 10:15 AM Advanced Principles of API Testing | Part 1 Presented by: Varuna Srivastava ThoughtWorks Canada Brought to you by: 8882688770 9042780524 [email protected] http://www.starcanada.techwell.com/

Transcript of Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design...

Page 1: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

   W4  API  Testing  Wednesday,  October  23rd,  2019  10:15  AM          

Advanced  Principles  of  API  Testing  |  Part  1  

 Presented  by:    

 

  Varuna  Srivastava    

ThoughtWorks  Canada    

Brought  to  you  by:        

   

   

888-­‐-­‐-­‐268-­‐-­‐-­‐8770  ·∙·∙  904-­‐-­‐-­‐278-­‐-­‐-­‐0524  -­‐  [email protected]  -­‐  http://www.starcanada.techwell.com/        

 

Page 2: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

     

Varuna  Srivastava    Varuna  is  a  technical  tester  who's  worked  on  award-­‐winning  projects  across  a  wide  variety  of  technology  sectors,  including  retail,  travel,  financial,  and  the  public  sector,  and  worked  with  various  web,  mobile,  and  IoT  technologies.  Varuna  is  a  passionate  advocate  of  shipping  quality  code  to  production  using  agile  practices.  When  not  working,  Varuna  likes  to  get  her  hands  dirty  experimenting  with  her  culinary  skills.  Most  of  her  weekends  are  spent  in  cookgraphy—cooking  plus  photography!    

Page 3: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Advanced Principles of API Testing

Page 4: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

About Me

● @vibranttester

Page 5: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Agenda

● Role of API’s

● API architecture

● What is API testing

● Types of api testing

● API documentation tools

● API design patterns

● API Test automation

Page 6: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Web services Sends test request

@vibranttester

Page 7: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Web services Sends test request

@vibranttester

Page 8: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

REST architecture

@vibranttester

Page 9: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API architecture

@vibranttester

Http headers Http

response

Http verbs

Http body

Page 10: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Http verbs

@vibranttester

POST DELETE

PUT

GET

Page 11: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Http headers

@vibranttester

Authorization Cache Control

Content Type

Set Cookie

Page 12: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Http headers → Set headers

@vibranttester

Page 13: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Http Response

@vibranttester

Page 14: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Rest API structure

@vibranttester

Page 15: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Testing

Page 16: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Test PyramidSends test request

@vibranttester

Page 17: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Testing (Adapted from watirmelon blog)

request

@vibranttester

Page 18: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Types Of API Testing

Page 19: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Types of API Testing

@vibranttester

Page 20: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Functional Tests

@vibranttester

● Focus on testing the functionality of respective api with valid inputs /searchItem By name By brand

Responsibility : ❖ Define scope of api❖ Verify edge case scenario ❖ Verify handled error scenario

Page 21: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Contract Tests

@vibranttester

● Focus on the messages that flow between a consumer and provider /orders

Responsibility : ❖ bugs in the consumer❖ misunderstanding from the consumer about end-points or payload❖ breaking changes by the provider on end-points or payload

Page 22: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Load Tests

@vibranttester

● Focus on verifying whether the theoretical solution works as a practical solution under a given load.

Responsibility : ❖ Verify how scalable apis are at maximum user load❖ Verify how quickly apis respond i.e speed❖ Verify if the apis are stable under varying loads

Page 23: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Security Tests

@vibranttester

● Focus is to make your data safe from hackers, and ensure that the API is as safe as possible

Responsibility : ❖ Validated external threats❖ Fuzz Testing❖ Penetration testing

Page 24: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Documentation

Page 25: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Swagger Sends test request

@vibranttester

Page 26: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Blueprint Sends test request

@vibranttester

Page 27: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Dredd commands

@vibranttester

Page 28: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Dredd result

https://app.apiary.io/public/tests/run/a017f6eb-e89e-4afe-8d49-327559c08d24

@vibranttester

Page 29: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

API Design Patterns

Page 30: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Design Patterns Sends test request

@vibranttester

Page 31: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Why Design Patterns in Test Automation? Sends test request

@vibranttester

ReliabilityScalability

Flexibility

Reusability Maintain ability

Page 32: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Types of Design Patterns Sends test request

@vibranttester

Creational

Behavioural

Structural

Page 33: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Structural Design Patterns

Page 34: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Structural Design Pattern

@vibranttester

Structural Design Patterns are used to avoid duplicates in code and increase the readability and navigation of code in project

Page 35: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Page Object Pattern

@vibranttester

HomePage Search Result Page Search Item

Item Search Tests

Page 36: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Page Object Pattern

@vibranttester

SearchItemTests.java SearchItemPage.java SearchItemId.java

Tests and method invocations

Method assertions

Identifier of an element

Page 37: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Page Object Pattern

@vibranttester

Page 38: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Page Factory Pattern

@vibranttester

Page Factory Pattern encapsulates page’s attribute by findby annotations.It helps to work directly with page fields hiding the low level complexity.

Page 39: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Page Factory Pattern

@vibranttester

Page 40: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Page Factory Pattern

@vibranttester

Page 41: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Page Factory Pattern

@vibranttester

Page 42: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Chain of Invocation Pattern

@vibranttester

Chain of invocation helps to avoid repeating object again and again before method invocations and makes code pretty!!

Page 43: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Chain of Invocation Pattern

@vibranttester

Page 44: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Chain of Invocation Pattern

@vibranttester

Page 45: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Chain of Invocation Pattern

@vibranttester

Page 46: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Strategy Design Pattern

@vibranttester

Strategy pattern is used whenever we want to have more than one implementations of the same action differently. It makes code more flexible and maintainable by using separation of concepts.

Page 47: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Data Design Patterns

Page 48: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Data Design Pattern

@vibranttester

Data Design Patterns are used to separate data and test logic.It reduces amount of data related code from test class.

Page 49: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Value Object Pattern

@vibranttester

Value Object makes code more readable and it reduces amount of repeatable constructions. It is immutable which avoid modifications and extensions.

Page 50: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊Builder Pattern

@vibranttester

Builder pattern makes process of building complex object easier.We don’t have to create multiple constructor for different scenario.

Page 51: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊DataProvider Pattern

@vibranttester

DataProvider pattern used to provide parameters to a test. A test method will be executed using the same instance of the test class to which the test method belongs.

Page 52: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Creational Design Patterns

Page 53: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊ Singleton Pattern

@vibranttester

Singleton class has only one instance, which provides a global access point to this instance.Singleton object is initialized only when it’s requested for the first time.

Page 54: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊ Singleton Pattern

@vibranttester

Example?

Page 55: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

◊ Singleton Pattern

@vibranttester

Example?

Page 56: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Let’s try this out !! API Test Automation

Page 57: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web

Comments..?Doubts..?Complains..?

Drop a note @vibranttester to continue this conversation Varuna Srivastava

LEAD QUALITY [email protected] | thoughtworks.com

Page 58: Advanced!Principles!ofAPI!Testing| Part!1!...Types of api testing API documentation tools API design patterns API Test automation. Web services Sends test request @vibranttester. Web