Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

A helper for cmockery

20 views
Skip to first unread message

Zhiming G

unread,
Feb 25, 2010, 1:18:31 PM2/25/10
to cmoc...@googlegroups.com
Here is a helper for cmockery. I think it is useful for simple unit tests in a single file.
After including <cmockery_easy.h>, we can write unit tests like this:

/////////////// begin of unit_tests.c//////////////////

#include <cmockery_easy.h>

ADD_TEST(test_1)
{
// do something
}

ADD_TEST(test_2)
{
// do something
}

RUN_TESTS_IN_MAIN();

/////////////// end of unit_tests.c//////////////////

In the upper example, test_1 and test_2 is declared as 
void test_1(void **state __attribute__((unused))); // gcc
void test_2(void **state __attribute__((unused)));
or
void test_1(void **state); // non gcc
void test_2(void **state);

The helper is attatched in this file. To use this helper, we need compile unit_tests.c with cmockery_easy.c and cmockery_easy_repeater.h in cmockery-easy.7z.

The helper use the macro __LINE__ as an identifier, so when writing a unit test source with more than 2048 lines, we should use "repeater_gen.c" in cmockery-easy.7z to generate a new "cmockery_easy_repeater.h" with custom parameters.
cmockery-easy.7z
Reply all
Reply to author
Forward
0 new messages