LibreSolar / bms-firmware

Firmware for LibreSolar BMS boards based on bq769x0, bq769x2 or ISL94202
https://libre.solar/bms-firmware/
Apache License 2.0
146 stars 67 forks source link

Restructure unit tests and migrate them to Ztest framework #48

Closed martinjaeger closed 7 months ago

martinjaeger commented 7 months ago

The unit tests were still based on UNITY as a test framework for legacy reasons (from a time where the BMS firmware was based on Mbed OS and PlatformIO).

The Zephyr Ztest framework has better built-in support for running with twister and doesn't require any external module. It's also just more common for Zephyr folks.

This PR converts all tests from UNITY to Ztest and restructures the tests from one single large test suite into dedicated suites for helper tools, different BMS ICs and common BMS features. This will make it easier to write unit test for future features like improved SOC calculation.

martinjaeger commented 7 months ago

To check floating points, you can use zassert_within, but it's not necessary for this PR.

Yeah, I've seen very funny things with floating point comparisons. I prefer to use zassert_equal whenever possible, so that you don't have to think about which tolerance you want to allow.

Thanks for the quick review!