Issue link:

Contents of this Issue


Page 14 of 24

May 2014 15 Unit Testing in C: Tools and Conventions Two lightweight testing frameworks make it easy to unit test C code. I n this article, I look at unit tests using two unit test harnesses that work in C. Along the way, I will also discuss some of the common terminology of automated unit testing. Let me start by discussing the fundamental tool: the test harness. What Is A Unit Test Harness? A unit test harness is a software package that allows a programmer to express how production code should behave. A unit test har- ness's job is to provide these capabilities: • A common language to express test cases • A common language to express expected results • Access to the features of the production code programming language • A place to collect all the unit test cases for the project, system, or subsystem • A mechanism to run the test cases, either in full or in partial batches • A concise report of the test suite success or failure • A detailed report of any test failures I'll shortly look at two popular harnesses for testing embedded C.They are both easy to use and are descendants of the xUnit family of unit test harnesses. First, I'll employ Unity, a C-only test harness ( Later, I will use CppUTest, a unit test harness written in C++, but not requiring C++ knowledge to use. You'll find that the bulk of the ma- terial in this article can be applied using any test harness. By James W. Grenning [ VAULT ] Table of Contents @jwgrenning Previous Next Previous Next Download Download Register Register Subscribe Subscribe Previous Next Previous Next From the Vault

Articles in this issue

Links on this page

view archives of InformationWeek - 423_DrDobbs