<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Advanced Features </TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Check Tutorial" HREF="index.html"><LINK REL="PREVIOUS" TITLE="SRunner output " HREF="x115.html"><LINK REL="NEXT" TITLE="No fork mode " HREF="x172.html"></HEAD ><BODY CLASS="CHAPTER" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Check Tutorial</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x115.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x172.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="CHAPTER" ><H1 ><A NAME="AEN163" ></A >Chapter 4. Advanced Features </H1 ><DIV CLASS="SECTION" ><H1 CLASS="SECTION" ><A NAME="AEN165" >4.1. Running multiple cases</A ></H1 ><P >What happens if we pass -1 as the amount in money_create? What should happen? Let's write a unit test. Since we are testing limits, we should also test what happens when we create money with amount 0: </P ><PRE CLASS="PROGRAMLISTING" >START_TEST (test_neg_create) { Money *m = money_create(-1, "USD"); fail_unless(m == NULL, "NULL should be returned on attempt to create with a negative amount"); } END_TEST START_TEST (test_zero_create) { Money *m = money_create(0, "USD"); fail_unless(money_amount(m) == 0, "Zero is a valid amount of money"); } END_TEST</PRE ><P >Let's put these in a separate test case, called “Limits” so that money_suite looks like so: </P ><PRE CLASS="PROGRAMLISTING" >Suite *money_suite (void) { Suite *s = suite_create("Money"); TCase *tc_core = tcase_create("Core"); TCase *tc_limits = tcase_create("Limits"); suite_add_tcase(s, tc_core); suite_add_tcase(s, tc_limits); tcase_add_test(tc_core, test_create); tcase_add_test(tc_limits, test_neg_create); tcase_add_test(tc_limits, test_zero_create); return s; }</PRE ><P >Now we can rerun our suite, and fix the problem(s). Note that errors in the Core test case will be reported as “Core” and errors in the Limits test case will be reported as “Limits,” giving you additional information about where things broke. </P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x115.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x172.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >SRunner output</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" > </TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >No fork mode</TD ></TR ></TABLE ></DIV ></BODY ></HTML >