+ All Categories
Home > Technology > Functional Testing of RESTful Applications

Functional Testing of RESTful Applications

Date post: 08-Feb-2017
Category:
Upload: nenad-bozic
View: 705 times
Download: 0 times
Share this document with a friend
26
Transcript
Page 1: Functional Testing of RESTful Applications
Page 2: Functional Testing of RESTful Applications

Functional Testing of RESTful Applications - Tools

and TechniquesOctober 2015

Nenad Bozic@NenadBozicNs

SmartCatwww.smartcat.io

@SmartCat_io

Page 3: Functional Testing of RESTful Applications

Why this presentation now

• Idea to do End-to-End tests is here for a long time (Selenium)

• Doing tests over presentation layer is hard

• Modern architecture separates client and server

• Servers with REST APIs ease up functional testing by skipping presentation

layer

Page 4: Functional Testing of RESTful Applications

Agenda

• Levels of tests

• Blackbox testing as monitoring tool

• Graybox testing as tool for external dependency control

• Bring functional tests closer to business with Cucumber

• Conclusion – tools and techniques overview

Page 5: Functional Testing of RESTful Applications

Levels of testing

• Unit testing

• Integration testing

• Component testing• Blackbox

• Whitebox

• Graybox

• System testing

“There are generally four recognized levels of tests: unit testing, integration testing, component interface testing, and system testing. Tests are frequently grouped by where they are added in the software development process, or by the level of specificity of the test.” - Wikipedia

Page 6: Functional Testing of RESTful Applications

Blackbox testing as monitoring tool

Page 7: Functional Testing of RESTful Applications

Blackbox testing as monitoring toolOverview of the system and goal of test

Page 8: Functional Testing of RESTful Applications

Blackbox testing as monitoring toolChallenge 1: Generate data

• Presentation from Gerard Meszaros was truly inspiring for our test data

• Hide test data in generators behind DSL

• Isolate data for easy cleanup

• Isolate data for testing in production

Page 9: Functional Testing of RESTful Applications

Blackbox testing as monitoring toolChallenge 2: Overcome latency in system

• Microservice architecture is bringing latency problems

• Spring Retry – setup number of attempts with pause in between

Page 10: Functional Testing of RESTful Applications

Blackbox testing as monitoring toolChallenge 3: Monitoring

• Save latest test result in memory

• Endpoint to fetch results of tests at any time

• Integration with Rollbar to log failed executions

• SMS/email notification strategy

Page 11: Functional Testing of RESTful Applications

Blackbox testing as monitoring toolResult: Tests as monitoring tool in production

• Scheduled tests with isolated data run each 10 minutes

• Health check of 5 applications in production (Rollbar integration and SMS/email notification)

• Test runs accessible via endpoint

• idea for future to have GUI and history of test runs

• Idea for future to save duration of tests so we can compare runs

• Admins sleep better at night

Page 12: Functional Testing of RESTful Applications

Graybox testing as tool for external dependency

control

Page 13: Functional Testing of RESTful Applications

Graybox testing as tool for external dependency controlOverview of the system and goal of test

Page 14: Functional Testing of RESTful Applications

Graybox testing as tool for external dependency controlChallenge 1: Mock external services

• Mock requests and provide controlled responses

• WireMock – library for stubbing and mocking web services

• Written in Java but provides a JSON API so you can use it with pretty much any language out there

• Application configuration challenges – use Spring Profiles to configure external URLs

• Local and functional environment use WireMock server

• Staging and production use real endpoints

Page 15: Functional Testing of RESTful Applications

Graybox testing as tool for external dependency controlChallenge 1: Mock external services

Page 16: Functional Testing of RESTful Applications

Graybox testing as tool for external dependency controlChallenge 2: Deployment flexibility

• WireMock has two ways of working:

• Standalone – configured via the Java API, JSON over HTTP or JSON files

• Library import – start server as part of the application

• WireMock is running and functional testing app sends rules and responses

Page 17: Functional Testing of RESTful Applications

Graybox testing as tool for external dependency controlResult: Fully tested flow with external dependencies before deployment

• Application is targeting WireMock instead of real external endpoints

• Functional testing application has controlled data which can be used for verification

• This approach can be used for internal dependencies as well

Page 18: Functional Testing of RESTful Applications

Bring functional tests closer to business with

Cucumber

Page 19: Functional Testing of RESTful Applications

Bring functional tests closer to business with CucumberWhy we decided to go with Cucumber

• Number of tests grew

• Code base of test application started to be hard to maintain

• Hard to group tests based on features

• Each person in the team had its own vocabulary and business perspective

• Our documentation got outdated faster and faster

Page 20: Functional Testing of RESTful Applications

Bring functional tests closer to business with CucumberOverview of Cucumber features

• You write scenarios and they are grouped in features

• Features can be tagged (@smoke-tests, @wire-mock)

• With @Before you can prepare environment for tests

• With @After you can do cleanup

• Everyone can write features which are translated to tests

• Dynamic documentation which is near code

Page 21: Functional Testing of RESTful Applications

Bring functional tests closer to business with CucumberFeature example

• Cucumber uses Gherkin notation (Given / When / Then)

• With Given you prepare application for test

• With When you issue command which will be tested

• With Then you state expected outcome

Given products CSV file for organization XWhen CSV file is uploaded to FTP server.Then the API call for organization X returns newly added products

Page 22: Functional Testing of RESTful Applications

Conclusion

Page 23: Functional Testing of RESTful Applications

Conclusion - tools and techniques overview

• Hint 1: try to organize data for testing directly in production

• Hint 2: use tools such as Spring Retry to overcome latency

• Hint 3: use tools such as WireMock to control dependencies

• Hint 4: use tools such as Cucumber to develop business language around

features

• Hint 5: schedule tests and leverage them as powerful monitoring tool

Page 24: Functional Testing of RESTful Applications

Links

• SmartCat Blog post - Blackbox testing microservices

• SmartCat Blog post - Graybox testing - Control your dependencies

• SmartCat Blog post - Bring functional tests closer to business with Cucumber

• Wikipedia testing levels in software

• Gerard Meszaros - Find the right abstraction for your tests

• Tools: Spring Retry, WireMock, Cucumber

Page 25: Functional Testing of RESTful Applications

Q&A

Page 26: Functional Testing of RESTful Applications

Thank you

Nenad Bozic@NenadBozicNs

SmartCatwww.smartcat.io

@SmartCat_io


Recommended