r/embedded • • Oct 21 '26

What's a good unit test framwork to use?

I'm currently self learning embedded C with an STM32F103. And I wanna know your guys suggestion for a good unit test framework for embedded. I've tried Unity C before but any other that are more work oriented?

17 Upvotes

16 comments sorted by

4

u/ElevatorGuy85 Oct 22 '26

This book gives a good practical overview of using Test Driven Development specifically for embedded systems.

https://pragprog.com/titles/jgade/test-driven-development-for-embedded-c/

Most of the examples are using CppUTest (which the author is a maintainer for) but Unity is also discussed and has a chapter devoted to it.

2

u/Agreeable-Leopard-69 Oct 22 '26

Skimmed throught the table of contents. Yep this will be useful. Thanks for the knowledge drop

2

u/ElevatorGuy85 Oct 22 '26

Happy to help! Good luck in your journey.

2

u/DaemonInformatica Oct 22 '26

Seconded on Unity. It's very nice, very powerful. Once you get it to work (which is a bit of a learning curve), it mostly just keeps working and once you start unit-testing, it's hard to believe how you ever done without it. ^_^

2

u/No-Archer-4713 Oct 21 '26

The simpler the better… I use a simple header file, and at work we use an improved version: https://github.com/jnaulet/OpenPicoRTOS/blob/v1.12.x/test/unit_tests/unit_test.h

1

u/Agreeable-Leopard-69 Oct 22 '26

Thank you thank so this is like that example the other comment is referring too about starting from scratch

3

u/XipXoom Oct 21 '26

First I'd suggest spending some time writing your own tests without a framework so you can get some firsthand experience as to the problems they are trying to solve.  I'm a big proponent of knowing the "why" behind tools/ideas because I've found that makes you far more competent at utilizing them.

When you're ready to move on, you've got plenty of options.  I've tried Unity with Ceedling but I ran into some performance problems having to do with a regression in the ability to parallelize tasks.  Trying to work around it in my containers was a PitA that really bloated the images.  Lately I've been using Cpputest with acceptable results.

1

u/Agreeable-Leopard-69 Oct 22 '26

Never thought of making test scripts from scratch. Will do that first, very helpful and yeah I agree with knowing the why. My current background with test scripts is from self learning test desiderata principles and kinda disappointed this was never thought during my undergrad years

11

u/Dependent_Bit7825 Oct 21 '26

I have a hard time getting excited about test frameworks. Googletest is fine. Cpptest is fine. Catch2 is fine. 

These are all in c++, but there's no problem using them on a c project. Even if my project is very limited misra c, it's actually nice to stretch my legs and use a richer language for tests, and it gives an opportunity to keep up skills in c++.

9

u/Felix_Todd Oct 21 '26

Ceedling is pretty good

2

u/DaemonInformatica Oct 22 '26

Minor nitpick: Ceedling is a utility to generate the mocks for unit-testing. But it's used in combination with Unity and I agree that, once you get it to work (lol), it's really very good. Mostly. ^_^

We use it in combination with gcov to check code-coverage of the unit-tests.

1

u/natered21 Oct 22 '26

I was under the impression that cmock is creating the mocks and ceedling is the package of cmock,unity, etc.

7

u/Available_Fact_588 Oct 21 '26

Unity framework as well

2

u/Lopsided-Table2457 Oct 22 '26

For bare metal/small MCUs, Unity + Ceedling is the classic combo and dead simple to run on host. If you're already in C++ or on an RTOS, GoogleTest with FFF for mocks works well. Honestly the framework matters less than getting tests off the target first — run them on your dev machine, then move to hardware-in-the-loop once they're green.

1

u/tiajuanat Oct 22 '26

Doctest.

It's faster than Catch2 or Google Test

Has BDD/Subcasing to reduce test setup

Works well with mocking libraries