Check the Return Value

The dominance of object-oriented design has not eliminated the use of the procedural models of API design. Use of and adaptation to older but ubiquitous procedural APIs such as POSIX suggest using returns and/or the global errno to communicate meaningful values corresponding to error conditions. Many POSIX calls, such as open(2),1 return an integer -1 on error and use a range of errno values for the error details.

1. See http://pubs.opengroup.org/onlinepubs/000095399/functions/open.html.

We have explored various ways to inject values into our code for testing purposes. We use those same techniques to inject procedural error codes. Commonly, we will thinly encapsulate procedural system APIs such as POSIX such that they ...

Get Quality Code: Software Testing Principles, Practices, and Patterns 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.