Transcript
Page 1: End to End Testing: Bug Squashing for API Developers

1

END TO END TESTING: BUG SQUASHING FOR API DEVELOPERS !

Ozan Seymen – Apigee Principal Architect Sean Davis – Apigee Technical Specialist

Page 2: End to End Testing: Bug Squashing for API Developers

API Testing - Agenda

2 ©2016 Apigee. All Rights Reserved.

•  Popular testing methodologies •  API testing best practices •  Popular open source tools

Page 3: End to End Testing: Bug Squashing for API Developers

Test Driven Development

3

Page 4: End to End Testing: Bug Squashing for API Developers

What is Test Driven Development?

• Understand the requirements • Write tests cases first (and let them fail!) • Write code to make tests pass • Refactor the code often

4 ©2016 Apigee. All Rights Reserved.

Page 5: End to End Testing: Bug Squashing for API Developers

What is Test Driven Development?

5 ©2016 Apigee. All Rights Reserved.

Page 6: End to End Testing: Bug Squashing for API Developers

Why use Test Driven Development?

•  Iterative development approach • Encourages thorough testing, ensuring “quality” • Tests are repeatable and can be automated • Confidence when iterating or refactoring legacy code

6 ©2016 Apigee. All Rights Reserved.

Page 7: End to End Testing: Bug Squashing for API Developers

Challenges

• Requirements must be well understood by developer • Focus on unit testing • QA team test effort still high • Maintaining set of common test cases

7 ©2016 Apigee. All Rights Reserved.

Page 8: End to End Testing: Bug Squashing for API Developers

Behavior Driven Development

8

Page 9: End to End Testing: Bug Squashing for API Developers

BDD

9 ©2016 Apigee. All Rights Reserved.

BDD is a software development process with TDD in its heart

Page 10: End to End Testing: Bug Squashing for API Developers

BDD – a software development process

10 ©2016 Apigee. All Rights Reserved.

Page 11: End to End Testing: Bug Squashing for API Developers

BDD – a software development process

11 ©2016 Apigee. All Rights Reserved.

Business analyst

developer

tester

Page 12: End to End Testing: Bug Squashing for API Developers

BDD – a software development process

12 ©2016 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

Page 13: End to End Testing: Bug Squashing for API Developers

BDD – Specifications

• Express using examples • Describe context, trigger and expected behaviour • Prioritize behaviours with business value

13 ©2016 Apigee. All Rights Reserved.

Page 14: End to End Testing: Bug Squashing for API Developers

BDD – Gherkin

14 ©2016 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

Page 15: End to End Testing: Bug Squashing for API Developers

BDD – Given/When/Then

15 ©2016 Apigee. All Rights Reserved.

Feature: As an Employee I want to buy a coffee so that I wake up in the morning Scenario: Buy one coffee Given there is 1 coffee left in the machine And I have deposited 50p When I press the coffee button Then I should be served a coffee

Page 16: End to End Testing: Bug Squashing for API Developers

BDD – Benefits of Gherkin

16 ©2016 Apigee. All Rights Reserved.

•  Documentation generation •  Executable specifications •  Tooling for editors •  Reusable snippets shared publicly •  Tools integration

Once you have standardized the language…

Page 17: End to End Testing: Bug Squashing for API Developers

17 ©2016 Apigee. All Rights Reserved.

Page 18: End to End Testing: Bug Squashing for API Developers

BDD – Tooling for Automated Testing

18 ©2016 Apigee. All Rights Reserved.

APICLI

YADDA

Page 19: End to End Testing: Bug Squashing for API Developers

BDD Testing with Apickli

19

github.com/apickli/apickli

•  apickli - REST API testing framework with cucumber.js •  Open source – no relationship to Apigee

©2016 Apigee. All Rights Reserved.

Page 20: End to End Testing: Bug Squashing for API Developers

Mocking

20

Page 21: End to End Testing: Bug Squashing for API Developers

Mocking

• Target API availability – Network, ops, deployment, migrations, patches – Parallel development

• Constantly changing/unpredictable data • Simulation of certain scenarios for testing • When tests rely on previous data population – e.g. forgotten password

• High latency on target

21 ©2016 Apigee. All Rights Reserved.

Page 22: End to End Testing: Bug Squashing for API Developers

Mocking

• API proxy – respond using policies • API proxy with node.js •  amok open source project - https://github.com/api-bucket/amok •  Import swagger and download server code from

http://editor.swagger.io/#/ • Other tools: – Mock Server – Wire Mock

22 ©2016 Apigee. All Rights Reserved.

Page 23: End to End Testing: Bug Squashing for API Developers

API Proxy Testing – Environments

23 ©2016 Apigee. All Rights Reserved.

Environment Apigee Target Data Type of testing DEV/TEST Mock Target Data and behavior from mocks Full Integration INTG Actual Backend (DEV) Data and behavior from DEV build of

target APIs Partial Integration

PERF Actual Backend (DEV/PERF) Data and behavior from DEV or PERF build of target APIs

Performance

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

Page 24: End to End Testing: Bug Squashing for API Developers

Unit Testing

24

Page 25: End to End Testing: Bug Squashing for API Developers

API Proxy Testing

25 ©2016 Apigee. All Rights Reserved.

Do you think it is possible to test an Apigee proxy fully with integration testing?

No…

Page 26: End to End Testing: Bug Squashing for API Developers

API Proxy Testing – Integration test enough?

26 ©2016 Apigee. All Rights Reserved.

Isolation/Coverage

Page 27: End to End Testing: Bug Squashing for API Developers

API Proxy Testing – Integration test enough?

27 ©2016 Apigee. All Rights Reserved.

Test Runner Apigee Target Systems

3rd Party Service Callouts? Async? Complex code?

Page 28: End to End Testing: Bug Squashing for API Developers

Unit Testing – Other benefits

• Code can be tested locally without deployment to Apigee first • Much faster than integration testing • Can create hooks to enforce testing during commit

28 ©2016 Apigee. All Rights Reserved.

Page 29: End to End Testing: Bug Squashing for API Developers

Unit Testing – Boundary Principal

29 ©2016 Apigee. All Rights Reserved.

Test within your boundaries – don’t test libraries you don’t control

Page 30: End to End Testing: Bug Squashing for API Developers

Unit Testing – Tooling

30 ©2016 Apigee. All Rights Reserved.

Page 31: End to End Testing: Bug Squashing for API Developers

Unit Testing

31

DEMO TIME!

Page 32: End to End Testing: Bug Squashing for API Developers

Questions?

32


Top Related