Date post: | 14-Apr-2017 |
Category: |
Technology |
Upload: | apigee-google-cloud |
View: | 962 times |
Download: | 2 times |
End To End Testing: !Bug Squashing For API Developers !
Ozan Seymen – Apigee Principal Architect Saulius Zukauskas – Apigee Principal Architect
API testing: agenda
©2015 Apigee. All Rights Reserved.
• Popular testing methodologies • API testing best practices • Popular open source tools
What is Test-driven development?
©2015 Apigee. All Rights Reserved.
• Understand the requirements. • Write test cases first (and let them all fail!). • Write code to make tests pass. • Refactor the code often.
What is important for TDD process to work?
©2015 Apigee. All Rights Reserved.
• Maintaining set of common test cases. • Getting all development team onboard. • If possible, get the product owners involved.
BDD
“You are not doing BDD until you embrace TDD”
KEEP CALM AND
EMBRACE TDD
(if you want to do proper BDD)
©2015 Apigee. All Rights Reserved.
BDD – a software development process
©2015 Apigee. All Rights Reserved.
Business analyst
developer
tester
DEFINE DOCUMENT USER STORIES TOGETHER!!!
BDD – a software development process
©2015 Apigee. All Rights Reserved.
define / document
automated "tests guide
provide feedback "on progress
specifications use as basis of tests
3 Amigos
developer
tester
business analyst
BDD – ¡Three Amigos!
©2015 Apigee. All Rights Reserved.
Specifications – what do they contain?
• Express the desired behavior and expected outcomes • Desired behavior that has business value • Express using examples (specification by example) • Outside-in
BDD – ¡Three Amigos!
©2015 Apigee. All Rights Reserved.
Specifications – How to specify?
• Semi-formal format borrowed from user story specifications • BDD imposes no rules – simplicity and standardization • Dan North and Chris Matts suggested Given/When/Then
BDD – Given/When/Then
©2015 Apigee. All Rights Reserved.
Given - Set of preconditions - State before action/trigger
When - An event occurs (trigger/action)
Then - Assert outcome of the event
GIVEN there is 1 coffee left in the machine and I have deposited 1$, WHEN I press the coffee button THEN I should be served a coffee.
Express behavior in terms of these statements:
BDD – Gherkin
©2015 Apigee. All Rights Reserved.
• When you come to document behavior, you need a language • Understood by humans and code • Gherkin – business readable, domain-specific language
BDD – Gherkin
©2015 Apigee. All Rights Reserved.
Feature: User trades stocks
Scenario: User requests a sell before close of trading
Given I have 100 shares of MSFT stock
And I have 150 shares of APPL stock
And the time is before close of trading
When I ask to sell 20 shares of MSFT stock
Then I should have 80 shares of MSFT stock
And I should have 150 shares of APPL stock
And a sell order for 20 shares of MSFT stock should have been executed
BDD – benefits of Gherkin
©2015 Apigee. All Rights Reserved.
• Documentation generation • Executable specifications • Tooling for editors • Reusable snippets shared publicly • Tools integration
Once you have standardized the language…
What is integration testing?
©2015 Apigee. All Rights Reserved.
• Very important for API development • Testing your software components as a group • Client to API + API to backend system
Integration testing tools for APIs
©2015 Apigee. All Rights Reserved. • 26 ©2015 Apigee. All Rights Reserved.
APICLI
YADDA
Integration testing flow – Apigee-based APIs
©2015 Apigee. All Rights Reserved.
Write test cases
Write API bundle code
Deploy API bundle code to Apigee
Run Integration
testing
Refactor
Apickli for API testing
©2015 Apigee. All Rights Reserved.
Scenario: As an ecommerce store user I would like to list all the available categories
Given I set User-Agent header to apickli And I set Accept header to application/json When I GET /v1/store/categories Then response code should be json And response code should be 200 And response body should contain categories
Apickli for API testing
©2015 Apigee. All Rights Reserved.
Scenario: Correct room availability to airbnb.com whenever I do single night booking Given that the resort [Resort] is set in airbnb.com And the room type [RoomType] is set up in airbnb.com And the hotel has [Available Rooms] rooms available for sale When I make a new single night booking Then airbnb.com should have [bcomNewRoomsToSell] rooms available
API proxy testing
©2015 Apigee. All Rights Reserved.
Do you think it is possible to test an Apigee proxy fully with integration testing?
No…
API proxy testing – integration test enough?
©2015 Apigee. All Rights Reserved.
Test Runner Apigee Target Systems
3rd Party Service callouts? Async?
Unit testing – other benefits
©2015 Apigee. All Rights Reserved.
• Code can be tested locally without deployment to Apigee first • Can create hooks to enforce testing during commit • Much faster than integration testing
Unit testing – boundary principle
©2015 Apigee. All Rights Reserved.
Test within your boundaries – don’t test libraries you don’t control
Unit testing - automation
©2015 Apigee. All Rights Reserved.
“Imperfect tests, run frequently, are much better than perfect tests that are rarely run”
Mocking – why?
©2015 Apigee. All Rights Reserved.
• Test backend systems are always down • Test backend systems are slow • Test backend systems have inconsistent data
End-to-end testing
©2015 Apigee. All Rights Reserved.
Oct 14 – 02:50PM APIGEE AND NODE.JS: BUILDING MOCK BACKENDS
API proxy testing – environments
©2015 Apigee. All Rights Reserved.
Environment Apigee Target Data Type of testing Development Mock Target Data and behavior from mocks Full Integration Integration Actual Backend (DEV) Data and behavior from DEV build of
target APIs Partial Integration
UAT Actual Backend (DEV/UAT) Data and behavior from DEV or UAT build of target APIs
Smoke
PRE Actual Backend (PROD) Data and behavior from target APIs in production
Smoke
PROD Actual Backend (PROD) Data and behavior from target APIs in production
Smoke
Smoke testing – API bundle deployed properly, access all target endpoints correctly, certificates deployed correctly, configuration is correct