Skip to content

feat(test): Add comprehensive unit and instrumentation tests#4260

Merged
jamesarich merged 8 commits into
mainfrom
feat/add_tests
Jan 20, 2026
Merged

feat(test): Add comprehensive unit and instrumentation tests#4260
jamesarich merged 8 commits into
mainfrom
feat/add_tests

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

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.

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>
@github-actions github-actions Bot added the enhancement New feature or request label Jan 19, 2026
@codecov

codecov Bot commented Jan 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (f8f3387) to head (d824134).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

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>
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>
@jamesarich jamesarich added this pull request to the merge queue Jan 20, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 20, 2026
@jamesarich jamesarich enabled auto-merge January 20, 2026 01:32
@jamesarich jamesarich added this pull request to the merge queue Jan 20, 2026
Merged via the queue into main with commit 45227fb Jan 20, 2026
9 checks passed
@jamesarich jamesarich deleted the feat/add_tests branch January 20, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant