GSoC 2023 with OpenMRS | Coding Week 09
After Midterm evaluation I started setting up the frameworks for testing as well as writing unit tests for the major repository files of the SDK. In the past weeks I finished unit tests of Appointment Repository and Visit Repository. These tests helped me identify existing issues and served as a solid foundation for future developments. By testing different edge cases, I was able to detect and address critical bugs that would have otherwise gone unnoticed.
Expanding Test Coverage:
In the past week, I extended the test coverage to include the Observation and Encounter Repositories. These repositories were essential components, and it was crucial to ensure their correctness. By adding new unit tests for these files, I could confidently verify their functionality and detect any potential regressions.
The Challenge: Creating Mock Injections
While Dagger Hilt brought significant benefits to the project, it also presented a challenge when it came to testing. In order to thoroughly test the SDK APIs, it was necessary to create mock injections for constructors. These mock injections would allow us to provide fake dependencies during testing, ensuring that we could test each component in isolation.
Initially, I found myself struggling to understand how to create these mock injections effectively. I delved into the official Android documentation for Hilt testing, hoping to find a straightforward solution. However, the complexity of the documentation left me scratching my head for a while.
I decided to take a step back and break down the problem into smaller parts. I began by revisiting the basics of dependency injection and the role of Dagger Hilt in managing dependencies.
To overcome the challenge of testing with Dagger Hilt, I realized that I needed to create extra providers for fake dependencies. These providers would supply the mock objects necessary for testing. By carefully designing these providers, I could ensure that the SDK APIs were tested thoroughly and in isolation
Discovering and Fixing Bugs (The Purpose achieved):
One of the most rewarding aspects of unit testing was the discovery of bugs in APIs that I had previously implemented. These bugs were lurking within the code but were exposed during the testing process. This was a testament to the effectiveness of unit testing, as it allowed me to pinpoint issues early and address them promptly.
So far…
I have added Unit tests for the following repositories:
- Appointment Repository
2. Visit Repository
3. Encounter Repository
4. Observation Repository
Thank you for reading and stay tuned for week 10 progress :)
Connect with me on LinkedIn: www.linkedin.com/in/amshubham