How to do Test Driven Development in Clean Architecture?
“Clean Code is Everywhere and Everywhere is the Clean Code”
The Test Driven Development is the proven model to build the quality software.
Yes, it is mandatory to the developer to build the appliation bug free at the same time it must be clean. Otherwise, it will create more issues while the number of feature increasing.
As per the Test Driven Development (TDD), the development should start from writing test cases
The TDD’s approach starts with
- Writing test cases
- Fix the issues in development
While coming to the Clean Architecture, it is the process of software development which gives the guidelines to the developer/product to build a quality software with more flexibility.
If we want to merge these two concepts to the product development, the following questions may raise
- What are the components to be covered in testing?
- How and what to mock?
- etc…
Clean architecture components
If we want to implement TDD on CA, the components of CA needs to be very clear at high level
The popular diagram shows the different components and it’s placement with the purpose.
Personally, I am following this architecture with little changes
- Entities
- Providers (which interact with external systems. Equalent to
Externam Interfaces
) - Repositories (The database related actions)
- Controllers (The API’s)
- Use cases
In this model, I am writing unit test cases for all the components except Providers.
I always create mock
for the providers. The role of repositories to call the provider and get the details convert to Entities and send back to usecases. The usecases then send back the entities to the controllers.