Programming · free software · the open webSubscribe via RSS

What Is a Good Test for Missing Sensor Values?

From the earlier reference collection. Read the current software blog.

Give null, absent, zero, and empty inputs separate test cases and documented meanings.

Distinguish missing from measured zero

A sensor reading of zero can be a real measurement. A missing value means the system has no usable measurement, and an empty string may indicate an incomplete or malformed field. Treating all three as false-like values can erase valid data or display a misleading zero.

Write down the input contract first. For example, a JSON field may be optional, may explicitly contain null, or may contain a numeric value. An empty string may be accepted only by a text import layer, where it can be translated into a missing state. Those decisions should be reflected in tests rather than left to incidental language behavior.

Build a four-case matrix

Create separate cases for an absent property, an explicit null, numeric zero, and an empty string. Assert the documented outcome for each: perhaps absent and null become “no reading,” zero remains a displayed measurement, and an empty string is rejected or normalized to missing. The exact policy varies; the important point is that each representation has a deliberate result.

Use a test table with input and expected state. This makes accidental collapsing easy to spot. A particularly revealing assertion checks that zero is not replaced by a fallback such as “—” merely because code uses a truthiness check.

Follow values through the interface

Test the parser and the presentation layer. The parser should preserve distinctions in its output model, while the dashboard should render them according to the product's language. If an absent field is unknown but an invalid string is an error, the screen or diagnostics may need different states.

Also test aggregation. A mean or minimum calculation should not silently include missing values as zero. Conversely, it should not discard a legitimate measured zero. Use a tiny dataset where the correct aggregate is easy to calculate, such as readings of zero and ten with one missing entry; the intended average of the present measurements is five if missing entries are excluded.

Make the outcome useful to operators

For each state, decide what metadata remains available: observation time, sensor identity, or an error reason. A missing observation should not inherit the timestamp of a previous valid value unless the interface labels that value as last known.

These tests turn vague “empty data” handling into a small, reviewable contract. When an import format changes, maintainers can update the cases deliberately and avoid confusing absence with a real physical reading.

Suggest a correction · All posts