Did you add the following to top of your source code to redirect the assert so it uses Cexception of the system assert?
#ifdef TEST
#undef assert
#include "CException.h"
#define assert(condition) if (!(condition)) Throw(0)
#endif
Then your source code can look like this:
#include <assert.h>
#ifdef TEST
#undef assert
#include "CException.h"
#define assert(condition) if (!(condition)) Throw(0)
#endif
void foo(struct mystruct_t* mystruct) {
// Assert when a null pointer is detected.
assert(NULL != mystruct);
// Do something with the struct.
mystruct->a = 1;
mystruct->b = 2;
}
Attached is helper include file for writing tests. It makes it easier to test for asserts. Add '#include "assert_unit_test_support.h"' to top of your test source file. I usually place the helper include file in the support folder. Then your test code can look like this:
#include "unity.c"
#inlcude "assert_unit_test_support.h"
#include "../inc/test.h"
void setUp(void)
{
// your setup code
}
void tearDown(void)
{
// your tear down code
}
void test_foo_asserts_on_null_struct(void)
{
// code should assert for NULL pointers
struct mystruct_t * null_struct = NULL;
TEST_ASSERT_FAIL_ASSERT(foo(null_struct));
// code should not assert for non-NULL pointers
struct mystruct_t valid_struct;
TEST_ASSERT_PASS_ASSERT(foo(&valid_struct));
}
Hope this helps.