WhoBuilt

Sub-second integration tests for your RN app & Bluetooth device

Oct 13, 2021· 22 min· 811 views·Watch on YouTube

Speaker

Lars Thorup, a freelance software engineer and open source developer from Denmark, explains how he built fast integration tests for React Native apps communicating with Bluetooth devices, drawing on work with Soundboks.

Why end-to-end tests fell short

Soundboks makes Bluetooth speakers controlled by a phone app, including features such as equalizer settings, speaker locking, and linking multiple speakers. Its Appium setup tested real phones and speakers, but about 15 scenarios took two and a half hours to run across devices. Runs could also fail inconsistently, slowing feedback on pull requests.

Recorded traffic combines speed with real messages

Handwritten mocks for react-native-ble-plx were hard to maintain and could keep passing after the device protocol changed. Thorup’s alternative records actual Bluetooth traffic from the app and device into JSON files, then reuses those recordings in Jest tests. The result retains messages observed in real device interactions while running without physical hardware.

Recording and replaying BLE interactions

A lightweight React Native recorder app runs on a phone against the real device and captures commands and events. App tests load the recording, render screens with React Testing Library, and advance through labeled points to check behavior. Thorup showed a connection test that exchanged around 50 BLE messages and ran in about 200 milliseconds.

Keeping recordings stable and useful

Recordings can use a canonical device ID so developers’ local devices do not create noisy file changes. For values that vary, such as battery level, the recorder can save a chosen canonical value while tests still check the actual reading against expectations. Teams can add handwritten traffic for boundary cases, and debug translations make UUIDs and encoded values easier to inspect.

Takeaways

  • Use recordings of real device traffic to make integration tests fast enough to run frequently.
  • Keep a small set of end-to-end tests for real-world timing and wireless behavior, while using recorded traffic for most automated checks.
  • Canonicalize device IDs and variable values to keep recording diffs stable across developers and runs.
  • Pair recorded integration coverage with handwritten cases for boundaries and combinations.
  • Add labels and readable debug translations to make BLE recordings easier to control and investigate.

Mentioned in this talk

Search inside this talk

What was claimed 8

Related talks