April 2011
Intermediate to advanced
356 pages
8h 55m
English
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.
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, |