Hi all Freifunk and GSoC communities!
The summer has gone and GSoC is almost finished! We did a good amount of work this summer, assuming challenges and historical issues, refactoring part of the code following good design patterns and automatizing the implemented tests on the Gitlab CI/CD. As you see, lots of different but related topics!
Milestones accomplished
- Refactor the code to use feature first pattern and split the logic and view:
https://gitlab.com/andrearuizrull/elRepo.io-android/-/merge_requests/6
https://gitlab.com/andrearuizrull/elRepo.io-android/-/merge_requests/5
https://gitlab.com/andrearuizrull/elRepo.io-android/-/merge_requests/4
- Refactor elRepo-lib to be mockable:
https://gitlab.com/andrearuizrull/elrepo-lib/-/merge_requests/2
- Fix historical issues:
https://gitlab.com/andrearuizrull/elrepo-lib/-/merge_requests/3
- Implement unit tests:
https://gitlab.com/andrearuizrull/elRepo.io-android/-/merge_requests/8
- Add test stage on Gitlab CI/CD:
https://gitlab.com/andrearuizrull/elRepo.io-android/-/merge_requests/7
https://gitlab.com/andrearuizrull/elRepo.io-android/-/pipelines/629815191
- MR to the main repo to merge the work done!
https://gitlab.com/elRepo.io/elRepo.io-android/-/merge_requests/8
https://gitlab.com/elRepo.io/elrepo-lib/-/merge_requests/2
https://gitlab.com/elRepo.io/retroshare-wrapper-dart/-/merge_requests/4
This is not only about unit testing
The GSoC project propose to implement unit testing on elRepo.io stack, but we had to do some work before it. Along with my mentors we made important changes on the elRepo.io stack code…
We refactored stuff!
On all the GSoC process we realized that elRepo.io-android had a lot of logic mixed with the UI: big Widgets that do a lot of stuff, very difficult to test. Beside my mentors, after the study of different patterns, we decided to do a big refactor of the application using a design pattern that makes elRepo.io-android more scalable, with the logic and the UI separated, and where the widgets was as much tiny as possible, following SOLID principles.
On this way, we cleaned up the code, splitting logic from UI, splitting UI on little pieces, and thinking the best way to organize the code on a feature first folder structure:
Also, elRepo-lib, was designed using top level functions, impossible to mock, which make it difficult to test. We refactored all the library following this answer to make it testable, using singletons and Mockito library to generate the code. After refactoring it, we can create mocks of elRepo-lib classes, so we can write the tests easier because we don’t need to mock all the API calls that any function of the elRepo-lib have to do (decreasing the number of lines of a test considerably)
And fixed historical issues
As I went so deep on the elRepo.io code, I was able to found a way to fix a UI historical issue. Mixing elRepo-lib native cache system with the Riverpod providers, on this refactor, we went able to implement our own self cache Riverpod based, letting us to improve the UI user experience without breaking elRepo-lib compatibility.
This, also bring us to find a Retroshare related issue:
https://gitlab.com/elRepo.io/elRepo.io-android/-/issues/67
But unit testing still there!
On all this oceans of refactors, bug fixing and substantial improvements, we still worked on the unit testing implementations.
Before the refactor, unit test was difficult, widgets where huge, elRepo-lib top level functions can’t be mocked, everything was slow and difficult to test. But after the refactor, the speed of writing a test increased exponentially.
We faced up how to test widgets, how to mock libraries self generating the code magically, stubbing functions, mocking responses, finding widgets etc… And, in addition, the app could be now developed easier using TDD (Test Driving Design) thanks of the refactor.
After all, we integrate a testing stage on the Gitlab Ci/CD for elRepo.io-android, which introduces superficially on the world of Docker and Gitlab pipelines.
Conclusion
GSoC was all the time an exciting experience that brought lots of challenges that I didn’t expect to find. There where some parts of the initial proposal that we didn’t achieve: integration tests for elRepo.io-android, or unit testing unit tests for elRepo-lib or for the retroshare-dart-wrapper.
But we achieved something more interesting and more valuable: we prepared all elRepo.io stack to work easily with a TDD workflow, we refactored substantially the code until the deeper parts of it. We prepared the app to be scalable, modular, and ordered to be easy to maintain, collaborate, or improve. Definitively, we pushed a step forward the quality of the code.
And I take with me a valuable present about how to test, and how to design apps. An important knowledge to continue helping on the development of this awesome app, and other flutter apps. I’m really happy to have been a GSoC participant this year.