Agile & TDD Best Practices for APIs: API Microservices Using TDD
APIs vs
Microservices
· An API is a contract between a caller
and an application underlying data and functionality
· APIs can be public (web based) or
private
· Web APIs usually send data in JSON or
XML
· Common API methods – GET, POST, PUT,
DELETE
· Microservices often include APIs
· Microservices are multiple component
services that can be combined to create a software solution
· Microservices are decentralized and
may have decentralized data
· Microservices are self-contained and
have dedicated data sources
TDD
· Mock services can be used to mock
REST APIs
· TDD allows clients to test APIs
before the coding is completed
· TDD API design process:
o
Tests
are written based on scenarios and required functionality
o
A
REST API mock service is created for running the test scenarios
o
Tests
are run on mock services
o
The
real APIs are created and run against the test scenarios
REST
API Mocking
Tools for
REST API mocking: Nock, MockServer, Beeceptor, Mockoon
Behavior
driven development (BDD) API design
· BDD is an agile development approach
· API design steps:
o
Select
a small unit of work, brainstorm and reach a consensus of API work to be done
o
Document
and track the API examples from the brainstorming session using automation
tools
o
Implement
the API web service behavior described in each example and create a unit test
to guide the implementation
· BDD involves all stakeholders, hence
it allow for a shared understanding of the problem domain, documentation is
created in general language, increases collaboration
· BDD supports better communication
between technical and non-technical people
· Natural language specifications and real-world
examples are used in BDD
· Tests generated in natural language
are automated in BDD
Software
testing techniques
· REST API testing
o
Functional
software testing
o
Security
testing
· Load testing
o
Determine
the maximum number of concurrent users
o
Infrastructure
stress tests check the server and network architecture
o
Maximum
operation capacity captures the total number of operations performed
· Database testing
o
Structural
testing to validate the architecture database
o
Functional
testing validates mapping between fields and functions
o
Non-functional
(example – security testing, load testing)
· Unit testing
Software testing tools
o
Web
testing platforms – Katalon Studio web testing tools (for validation testing,
error detection testing and functional testing, SOAP UI REST API testing)
o
SOAP
and REST API testing tools
o
Tools
for unit testing
Integration
testing
3 methods to
write -> Create test (to setup the resources such as the DB), read test and
delete test (to clean up the resources such as DB)
Tools –
Postman
No comments:
Post a Comment