Functional Testing of RESTful Applications Tools and Techniques

  • Slides: 26
Download presentation

Functional Testing of RESTful Applications - Tools and Techniques October 2015 Nenad Bozic @Nenad.

Functional Testing of RESTful Applications - Tools and Techniques October 2015 Nenad Bozic @Nenad. Bozic. Ns Smart. Cat www. smartcat. io @Smart. Cat_io

Why this presentation now • Idea to do End-to-End tests is here for a

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

Agenda • Levels of tests • Blackbox testing as monitoring tool • Graybox testing

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

Levels of testing “There are generally four recognized levels of tests: unit testing, integration

Levels of 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 • Unit testing • Integration testing • Component testing • Blackbox • Whitebox • Graybox • System testing

Blackbox testing as monitoring tool

Blackbox testing as monitoring tool

Blackbox testing as monitoring tool Overview of the system and goal of test

Blackbox testing as monitoring tool Overview of the system and goal of test

Blackbox testing as monitoring tool Challenge 1: Generate data • Presentation from Gerard Meszaros

Blackbox testing as monitoring tool Challenge 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

Blackbox testing as monitoring tool Challenge 2: Overcome latency in system • Microservice architecture

Blackbox testing as monitoring tool Challenge 2: Overcome latency in system • Microservice architecture is bringing latency problems • Spring Retry – setup number of attempts with pause in between

Blackbox testing as monitoring tool Challenge 3: Monitoring • Save latest result in memory

Blackbox testing as monitoring tool Challenge 3: Monitoring • Save latest result in memory • Endpoint to fetch results of tests at any time • Integration with Rollbar to log failed executions • SMS/email notification strategy

Blackbox testing as monitoring tool Result: Tests as monitoring tool in production • Scheduled

Blackbox testing as monitoring tool Result: 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

Graybox testing as tool for external dependency control

Graybox testing as tool for external dependency control

Graybox testing as tool for external dependency control Overview of the system and goal

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

Graybox testing as tool for external dependency control Challenge 1: Mock external services •

Graybox testing as tool for external dependency control Challenge 1: Mock external services • Mock requests and provide controlled responses • Wire. Mock – 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 Wire. Mock server • Staging and production use real endpoints

Graybox testing as tool for external dependency control Challenge 1: Mock external services

Graybox testing as tool for external dependency control Challenge 1: Mock external services

Graybox testing as tool for external dependency control Challenge 2: Deployment flexibility • Wire.

Graybox testing as tool for external dependency control Challenge 2: Deployment flexibility • Wire. Mock 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 • Wire. Mock is running and functional testing app sends rules and responses

Graybox testing as tool for external dependency control Result: Fully tested flow with external

Graybox testing as tool for external dependency control Result: Fully tested flow with external dependencies before deployment • Application is targeting Wire. Mock 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

Bring functional tests closer to business with Cucumber

Bring functional tests closer to business with Cucumber

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

Bring functional tests closer to business with Cucumber Why 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

Bring functional tests closer to business with Cucumber Overview of Cucumber features • You

Bring functional tests closer to business with Cucumber Overview 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

Bring functional tests closer to business with Cucumber Feature example • Cucumber uses Gherkin

Bring functional tests closer to business with Cucumber Feature 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 X When CSV file is uploaded to FTP server. Then the API call for organization X returns newly added products

Conclusion

Conclusion

Conclusion - tools and techniques overview • Hint 1: try to organize data for

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 Wire. Mock 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

Links • Smart. Cat Blog post - Blackbox testing microservices • Smart. Cat Blog

Links • Smart. Cat Blog post - Blackbox testing microservices • Smart. Cat Blog post - Graybox testing - Control your dependencies • Smart. Cat 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, Wire. Mock, Cucumber

Q&A

Q&A

Thank you Nenad Bozic @Nenad. Bozic. Ns Smart. Cat www. smartcat. io @Smart. Cat_io

Thank you Nenad Bozic @Nenad. Bozic. Ns Smart. Cat www. smartcat. io @Smart. Cat_io