This PR introduces a series of enhancements focused on improving unit test coverage and refactoring for clarity and maintainability inside our models/view-models.
Tests added
in FoodFactsViewModelTest.kt:
Tested that Factory companion object correctly instantiates a ViewModel and throws an exception when given an unknown ViewModel class
in OpenFoodFactsRepositoryTest.kt:
Fixed current tests that were not actually checking properly their results. Used CountDownLatch for OnSuccess and OnFailure cases, in order to wait before checking results
in FoodItemTest:
Added tests for getImportantDetails, getRemainingDays, isExpired, and edge case handling in helper functions.
in ListItemsViewModelTest:
Tested failure logging on repository errors, confirmed Factory behavior, and validated exception handling for unknown ViewModel classes.
in HouseHoldViewModelTest:
Leveraged ShadowLog to validate error logging on failure, tested updates to Household flows, and verified functions like checkIfHouseholdNameExists work with both populated and empty lists.
Small modifications outside Tests:
Refactored OpenFoodFactsRepository:
Added a buildUrl function to streamline URL construction, avoiding potential double-slash issues. This was especially relevant for the testing with mock URLs.
Improved FoodItem Output:
Updated getImportantDetails in FoodItem.kt to produce a cleaner, more readable string.
Updated ListFoodItemsViewModel Factory:
Modified the Factory object in ListFoodItemsViewModel to accept a FoodItemRepository as a parameter, enhancing flexibility.
Purpose and Impact
This PR is heavily focused on testing to meet M1 feedback criteria and enhance code reliability and readability.
The current batch of tests achieves nearly 95% for model/foodfacts, household, foodItem packages.
Future Improvement
FoodItemRepositoryFirestore needs a test for the init. This however requires some complex mocking of the authorised user, which I was not able to acheive in this PR. ToDo in a future task!
PR: Test/127 - Implement M1 Feedback Concerning Testing
Summary:
This PR introduces a series of enhancements focused on improving unit test coverage and refactoring for clarity and maintainability inside our models/view-models.
Tests added
Factory
companion object correctly instantiates a ViewModel and throws an exception when given an unknown ViewModel classCountDownLatch
forOnSuccess
andOnFailure
cases, in order to wait before checking resultsgetImportantDetails
,getRemainingDays
,isExpired
, and edge case handling in helper functions.Factory
behavior, and validated exception handling for unknown ViewModel classes.ShadowLog
to validate error logging on failure, tested updates toHousehold
flows, and verified functions likecheckIfHouseholdNameExists
work with both populated and empty lists.Small modifications outside Tests:
buildUrl
function to streamline URL construction, avoiding potential double-slash issues. This was especially relevant for the testing with mock URLs.getImportantDetails
inFoodItem.kt
to produce a cleaner, more readable string.Factory
object inListFoodItemsViewModel
to accept aFoodItemRepository
as a parameter, enhancing flexibility.Purpose and Impact
This PR is heavily focused on testing to meet M1 feedback criteria and enhance code reliability and readability.
Future Improvement
FoodItemRepositoryFirestore
needs a test for the init. This however requires some complex mocking of the authorised user, which I was not able to acheive in this PR. ToDo in a future task!