Skip to Main Content
Test Driven Development for Embedded C
book

Test Driven Development for Embedded C

by James W. Grenning
April 2011
Intermediate to advanced content levelIntermediate to advanced
356 pages
8h 55m
English
Pragmatic Bookshelf
Content preview from Test Driven Development for Embedded C

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, ​
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design Patterns for Embedded Systems in C

Design Patterns for Embedded Systems in C

Bruce Powel Douglass

Publisher Resources

ISBN: 9781941222997Errata Page