Unity: A C-Only Test Harness
Unity is a straightforward, small unit test harness. It is comprised of just a few files. Let’s get familiar with Unity and unit tests by looking at a couple example unit test cases. If you are a long-time Unity user, you’ll notice some additional macros that are helpful when you are not using Unity’s scripts to generate a test runner.
sprintf Test Cases in Unity
A test should be short and focused. Think of it as an experiment that silently does its work when it passes but makes some noise when it fails. This test checks that sprintf handles a format spec with no format operations.
unity/stdio/SprintfTest.c | |
| TEST(sprintf, NoFormatOperations) |
| { |
| char output[5]; |
| |
| TEST_ASSERT_EQUAL(3, sprintf(output, |
Get Test Driven Development for Embedded C now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.