Unit Testing

Purpose

Unit tests in this repository are designed to validate component behavior, not entrypoint wiring.

Test stack

The project uses PlatformIO’s unit testing framework with Unity.


Test layout

Tests are organized by ownership and module:

test/
├─ common/
│  ├─ test_bucketed_pqueue/
│  ├─ test_kv_pool/
├─ sensor_board/
│  ├─ test_gps_sensor/
│  ├─ test_imu_sensor/
│  ├─ test_ph_sensor/
│  ├─ test_sensor_basics/
├─ driving_board/
│  ├─ test_calculator/
│  ├─ test_motor/
├─ debugging_board/
│  ├─ test_input_handler/
├─ unity_config.c
└─ unity_config.h

Naming conventions:

Running tests

Run all tests for a specific environment:

pio test -e sensor_board

Run all tests across all environments:

pio test

Run a specific test directory:

pio test -e sensor_board -f test_imu_sensor

Environment test selection (platformio.ini)

Test execution is controlled per environment using the test_filter setting.

Current configuration:

When adding new tests, ensure the corresponding environment includes the test path in its test_filter. Otherwise, the tests will not be executed.

Writing a new unit test

1) Place it by ownership

Tests must follow the same ownership structure as the components.

Example:

2) Use Unity structure

#include "unity.h"

void setUp(void) {}
void tearDown(void) {}

void test_example_behavior(void) {
    TEST_ASSERT_TRUE(1);
}

int main(void) {
    UNITY_BEGIN();
    RUN_TEST(test_example_behavior);
    return UNITY_END();
}

3) Assert behavior, not implementation

4) Keep tests deterministic

What to test

What not to test as unit tests

The following are outside the scope of unit testing:

These belong to integration or system-level testing.

Troubleshooting


Revision #1
Created 2026-04-16 07:47:58 UTC by Nikolaos Diamantopoulos
Updated 2026-04-16 07:49:24 UTC by Nikolaos Diamantopoulos