Testing Backend Error Handling and Its Analytics on a Roku App with a Fake Server

Testing Backend Error Handling and Its Analytics on a Roku App with a Fake Server

Most apps are tested against a backend that works. The interesting bugs, though, live in the paths where it doesn't: a 500 at login, a timeout, a response that isn't valid JSON. Those paths are hard to reach with a real server, and when the app reports errors to analytics, testing them carelessly can also fill production dashboards with fake failures.

We recently tested exactly this on a Roku app: how it handles backend errors, and which error events it tries to report. Here is the setup, the rules we followed, and what we found.

A fake backend on the local network

Instead of the real account and user API, the app talked to a small fake server: a Python 3 script using only the standard library, running on a Mac on the same network as the Roku. It logged every request it received.

The error mode was chosen by the request path, and we made one test build per case, so each build hit exactly one scenario. The cases were:

  • a normal successful response,
  • HTTP 500 and HTTP 404,
  • a timeout and a dropped connection,
  • a response with broken JSON,
  • business errors: a valid response carrying an application error code.

Each case could be applied either at the first authorization call or at a later call during normal use.

Keeping analytics out of production

The tests were about error analytics, but we did not want a single test event in production. So we neutralized analytics instead of capturing it:

  • the test builds existed only on the test machine and were never committed,
  • the backend address pointed to the fake server,
  • every analytics address pointed to a dead local address, so nothing could leave the device,
  • the third-party analytics SDK was switched off.

Before every install we checked the addresses in the build, with one simple rule: if a production host ever shows up in the device console, stop. We also avoided opening content tiles during tests, because another component could send real analytics from there.

What we checked

Even with analytics going nowhere, the app still tried to send its error events, and those attempts were visible in the Roku debug console. We compared them with the labels the web version of the same app sends for the same errors, and cross-checked with the fake server's log to see which endpoints were actually hit.

All HTTP, business-error and broken-JSON cases produced the expected label and code. The more useful part was what else turned up.

What we found

  • Startup errors were lost. Errors that happened before the analytics module was initialized were simply dropped. The fix was a small pending queue that is flushed once the module is ready.
  • A dropped connection looks like a timeout. On Roku, a reset connection gives no response callback, only a timeout, so it is reported as a timeout. We accepted this as a platform limit and documented it.
  • Broken JSON crashed the app. An existing handler read a nested field after parsing had already failed. We only found it because the fake server could return garbage on purpose.
  • A type mismatch. The error field was being filled with a request object instead of an error dictionary, which showed up as a warning.
  • "200" is not the same as success. A save handler treated any HTTP 200 as success without looking at the body.
  • The log showed coverage gaps. Errors on later calls needed specific UI actions to trigger, and switching between users could not be tested with a single fake user. Reading the server log made those gaps obvious.

A process lesson

Once, two test runs drove the same device at the same time, and one of them reinstalled a build that pointed to the real backend. The rule since then is clear: one test run per device, and check what build is on the device when the run is done.

Takeaway

  • A tiny fake server that can return any error on demand finds bugs a working backend never will, especially for malformed responses.
  • When testing error analytics, make it impossible for events to leave the device, and verify that before every install.
  • Watch what the app tries to send; you don't need to receive events to check them.
  • Know your platform's limits, like a reset that only looks like a timeout, and document them.
  • Treat the test device as a shared resource: one run at a time, and check its state afterwards.
Go To All Articles