Skip to content

test(hts221): Add mock unit tests for HTS221 driver.#169

Open
Charly-sketch wants to merge 1 commit into
mainfrom
feat/hts221-mock-test
Open

test(hts221): Add mock unit tests for HTS221 driver.#169
Charly-sketch wants to merge 1 commit into
mainfrom
feat/hts221-mock-test

Conversation

@Charly-sketch
Copy link
Copy Markdown
Contributor

test(hts221): Add mock unit tests (#22)

Add native unit tests for the HTS221 driver using MockWire.
Closes #22

Covers:

  • Device detection (WHO_AM_I, begin)
  • Power and modes (powerOn/off, setContinuous, triggerOneShot)
  • Status flags (dataReady, temperatureReady, humidityReady)
  • Measurement APIs (read, temperature, humidity, readOneShot)
  • Behavior (auto-trigger in one-shot, no trigger in continuous)
  • Error handling (timeout → NaN)
  • Processing (humidity clamp, temperature offset, user calibration)
  • Reset (reboot, softReset)

Add comprehensive desktop unit tests for the HTS221 Arduino driver using MockWire.

This introduces a full native test suite covering the public API and core behaviors
of the driver, aligned with the project testing conventions and MicroPython scenarios.

Key additions:
- Device detection:
  - Test WHO_AM_I register via deviceId()
  - Test begin() success and failure cases

- Power and modes:
  - Test powerOn() / powerOff()
  - Test setContinuous() (ODR + PD bit)
  - Test triggerOneShot()

- Status handling:
  - Test dataReady(), temperatureReady(), humidityReady()
  - Test partial readiness cases

- Measurement logic:
  - Test read(), temperature(), humidity()
  - Test readOneShot()
  - Verify auto-trigger behavior when powered off
  - Verify no trigger in continuous mode

- Error handling:
  - Test timeout behavior returning NaN when data is not ready

- Calibration and processing:
  - Test humidity clamping (0–100%)
  - Test temperature offset application
  - Test user calibration via calibrateTemperature()

- Reset:
  - Test reboot() and softReset() register writes

- Shared contract checks:
  - Integrate driver_checks.h helpers for begin() and WHO_AM_I

All tests pass in native environment using:
pio test -e native

Notes:
- Tests are adapted to the current MockWire capabilities (no reset/onRead hooks)
- Calibration register mutation tests were avoided in favor of public API testing
  for reliability and determinism

Depends on:
- test framework setup (#20)
- MockWire implementation (#21)
@Charly-sketch Charly-sketch requested a review from nedseb May 6, 2026 12:49
@github-actions github-actions Bot added the test Tests and test infrastructure label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Tests and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(hts221): Add mock unit tests.

2 participants