Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>We started some work with CUnit, which worked except that everything ran in one thread and any memory faults caused the unit tests to stop running, which was rather annoying. </p> </blockquote> <p>There one C unit testing framework that forks and executes each test cases in a separate process so that all the tests are executed even in the presence of tests that core dump : <a href="http://sourceforge.net/projects/check/" rel="nofollow noreferrer">Check</a> </p> <p>However, I'm afraid of the performance penalty all these forks bring (and to be honest, I didn't give it a try). But I won't live long with any single test core dumping : I usually fix it immediately. </p> <p>One trick to prevent the unit tests to core is the <strong><a href="http://xunitpatterns.com/Guard%20Assertion.html" rel="nofollow noreferrer">assertion guard</a></strong>, for instance: use an assertion to prevent using a NULL pointer (example with <a href="http://www.jera.com/techinfo/jtns/jtn002.html" rel="nofollow noreferrer">minunit</a>). </p> <pre><code>void test_function_returning_a_pointer(void) { struct_t *theStruct = function_returning_a_pointer(); MU_ASSERT(theStruct != NULL); //--- now you can use the pointer MU_ASSERT(theStruct-&gt;field1 == 0); return MU_PASSED; } </code></pre> <p>By the way, I'm not aware of any C++ unit test framework that won't crash in case of segmentation violation.</p> <blockquote> <p>I also found it incredibly difficult to write the tests, but that might just be unit testing for you.</p> </blockquote> <p>Could you elaborate on your difficulties ? Are you trying to put legacy code under tests ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload