feat(test): Add comprehensive unit and instrumentation tests#4260
Merged
Conversation
This commit introduces a suite of new unit and instrumentation tests across various modules, significantly improving test coverage and code stability. It also includes several related bug fixes and minor refactorings identified during test creation.
### Key Changes:
- **Test Suite Expansion:**
- **Service Layer (`app` module):**
- `MeshCommandSender`: Validates that a default hop limit of 3 is used when the device's configured limit is 0.
- `MeshConnectionManager`: Tests connection state transitions, including handling of `DeviceSleep` state with and without power saving enabled.
- `MeshMessageProcessor`: Verifies that incoming packets are buffered when the node database is not ready and flushed correctly once it becomes available.
- `FromRadioPacketHandler`: Ensures correct routing of `FromRadio` packets (`MyInfo`, `Metadata`, `NodeInfo`, etc.) to the appropriate handlers.
- `PacketHandler`: Tests packet queuing and sending logic based on connection state.
- `MeshNodeManager`: Refactored tests to use mocks, covering scenarios like preserving user details on incoming default user data.
- `MeshDataMapper`: Improved tests for mapping protobuf `MeshPacket` to the app's `DataPacket` model.
- **Radio Interfaces (`app` module):**
- `StreamInterface`: Added tests for byte stream parsing logic, covering various packet sizes and error conditions.
- `TCPInterface`: Added a test to verify correct heartbeat packet generation.
- **Core & Feature Modules:**
- `MeshLogRepository` (`core/data`): Added tests to confirm that a temperature value of `0.0` is correctly preserved and not treated as a missing value.
- `MetricsViewModel` (`feature/node`): Added tests for environment metrics filtering and state calculation.
- `BleOtaTransport` (`feature/firmware`): Verifies that the MTU is requested upon connection.
- **Bug Fixes & Refinements:**
- **Hop Limit:** `MeshCommandSender` now enforces a default hop limit of `3` if the device's configuration is `0`, preventing packets from being dropped immediately.
- **Temperature Display:**
- The `MetricsViewModel` now correctly respects the global `IMPERIAL` display unit for showing temperature in Fahrenheit, in addition to the specific module setting.
- Fixed a bug where a valid temperature of `0.0` was not being displayed; it is now correctly handled as a valid metric and not filtered out as `NaN`.
- **QR Code UI:**
- When adding new channels via a QR code (not replacing), existing channels are now correctly preserved and visually disabled in the selection dialog.
- Added more descriptive text to the QR code dialog to clarify the difference between adding channels and replacing the entire configuration.
- **Build & Dependency Management:**
- Added `Robolectric`, `MockK`, and other testing libraries to `app` and `feature/node` modules.
- Enabled Android resources in unit tests for the `feature/node` module.
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4260 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 3 3
Lines 23 23
Branches 7 7
=====================================
Misses 23 23 ☔ View full report in Codecov by Sentry. |
This commit refactors `MeshConnectionManagerTest` to enhance its stability and correctness by addressing issues with coroutine testing and protobuf object creation.
- **Coroutine Testing:** Switched from `StandardTestDispatcher` and `TestScope` to `UnconfinedTestDispatcher` and `runTest(dispatcher)`. This change improves the reliability of asynchronous test execution and simplifies test structure.
- **Protobuf Initialization:** Updated the creation of `LocalConfig` and `Config` objects to use the standard builder pattern (`LocalConfig.newBuilder()`) instead of the deprecated `localConfig {}` DSL.
- **Resource Mocking:** Added mocking for `StringResources` to prevent `MissingResourceException` during test runs, ensuring that UI-related string lookups do not cause test failures.
- **Assertions:** Replaced simple `assert()` calls with JUnit's `assertEquals()` for more descriptive failure messages.
- **Test Logic:** Enhanced the `Disconnected state stops services` test to ensure it transitions through a `Connected` state first, guaranteeing the `Disconnected` state change has a meaningful effect to verify.
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit refines the Kover code coverage and Dokka documentation generation configurations for better consistency and correctness in a multi-module project. ### Key Changes: - **Kover Coverage Reports:** - Updated GitHub Actions workflows (`reusable-android-build.yml` and `reusable-android-test.yml`) to use a glob pattern (`"**/build/reports/kover/report.xml"`) for locating Kover reports. This ensures that reports from all submodules are correctly found and uploaded to Codecov. - Enabled XML and HTML total reports in the root `build-logic` convention plugin, which simplifies report aggregation. - Added `testDebugUnitTest` to the build workflow to ensure all relevant unit tests are executed. - **Dokka Documentation:** - Removed redundant manual source set discovery logic from the `Dokka.kt` convention plugin. The Dokka plugin is now capable of automatically finding Android source sets, making the explicit configuration unnecessary. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit updates the `ScannedQrCodeDialogTest` to correctly reflect the intended behavior of preserving specific local LoRa configuration fields (`configOkToMqtt` and `txPower`) when importing a new channel set from a QR code. The test assertion has been modified to create an `expectedChannelSet` that copies these preserved fields from the original local configuration into the incoming channel set. This ensures the test accurately verifies that these local settings are not overwritten during the import process. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit adds `performScrollTo()` actions to the UI tests for the `ScannedQrCodeDialog`. This ensures that test assertions and click actions can find and interact with buttons that may be off-screen on smaller display devices, preventing test failures due to visibility issues. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces a suite of new unit and instrumentation tests across various modules, significantly improving test coverage and code stability. It also includes several related bug fixes and minor refactorings identified during test creation.
Key Changes:
Test Suite Expansion:
appmodule):MeshCommandSender: Validates that a default hop limit of 3 is used when the device's configured limit is 0.MeshConnectionManager: Tests connection state transitions, including handling ofDeviceSleepstate with and without power saving enabled.MeshMessageProcessor: Verifies that incoming packets are buffered when the node database is not ready and flushed correctly once it becomes available.FromRadioPacketHandler: Ensures correct routing ofFromRadiopackets (MyInfo,Metadata,NodeInfo, etc.) to the appropriate handlers.PacketHandler: Tests packet queuing and sending logic based on connection state.MeshNodeManager: Refactored tests to use mocks, covering scenarios like preserving user details on incoming default user data.MeshDataMapper: Improved tests for mapping protobufMeshPacketto the app'sDataPacketmodel.appmodule):StreamInterface: Added tests for byte stream parsing logic, covering various packet sizes and error conditions.TCPInterface: Added a test to verify correct heartbeat packet generation.MeshLogRepository(core/data): Added tests to confirm that a temperature value of0.0is correctly preserved and not treated as a missing value.MetricsViewModel(feature/node): Added tests for environment metrics filtering and state calculation.BleOtaTransport(feature/firmware): Verifies that the MTU is requested upon connection.Bug Fixes & Refinements:
MeshCommandSendernow enforces a default hop limit of3if the device's configuration is0, preventing packets from being dropped immediately.MetricsViewModelnow correctly respects the globalIMPERIALdisplay unit for showing temperature in Fahrenheit, in addition to the specific module setting.0.0was not being displayed; it is now correctly handled as a valid metric and not filtered out asNaN.Build & Dependency Management:
Robolectric,MockK, and other testing libraries toappandfeature/nodemodules.feature/nodemodule.