Power Up Your Flutter Development Process by Implementing Clean Architecture and Test-Driven Development | by Aditya Rohman | Feb, 2022

lib
├── data
│ ├── constants.dart
│ ├── datasources
│ │ └── remote_data_source.dart
│ ├── exception.dart
│ ├── failure.dart
│ ├── models
│ │ └── weather_model.dart
│ └── repositories
│ └── weather_repository_impl.dart
├── domain
│ ├── entities
│ │ └── weather.dart
│ ├── repositories
│ │ └── weather_repository.dart
│ └── usecases
│ └── get_current_weather.dart
├── injection.dart
├── main.dart
└── presentation
├── bloc
│ ├── weather_bloc.dart
│ ├── weather_event.dart
│ └── weather_state.dart
└── pages
└── weather_page.dart
test
├── data
│ ├── datasources
│ │ └── remote_data_source_test.dart
│ ├── models
│ │ └── weather_model_test.dart
│ └── repositories
│ └── weather_repository_impl_test.dart
├── domain
│ └── usecases
│ └── get_current_weather_test.dart
├── helpers
│ ├── dummy_data
│ │ └── dummy_weather_response.json
│ ├── json_reader.dart
│ ├── test_helper.dart
│ └── test_helper.mocks.dart
└── presentation
├── bloc
│ └── weather_bloc_test.dart
└── pages
└── weather_page_test.dart

Step – 1: Write the code on the domain layer

Use cases

flutter pub run build_runner build
Get the current weather use case test result

Step – 2: Write the code on the data layer

Models

Model test result

data sources

Sample of JSON response
Data source test result

warehouses

flutter pub run build_runner build
Warehouse test result

The third step: write the code on the display layer

state administration (Mass)

flutter pub run build_runner build
BLoC Case Management Test Result

Pages

Page test result
The final result
flutter test --coverage
genhtml coverage/lcov.info -o coverage/html
open coverage/html/index.html
Test coverage result

Leave a Comment