I am working on an embedded C project where there is a function used to initialise a module's (foo) context object handle. Thus when testing using the Ceedling I have used this initialising function in the set up:
#include "unity.h"
#include "mock_bar.h"
#include "foo.h"
static foo_handle s = NULL;
void setUp(void)
{
s = foo_init(&bar_assertAlert, &bar_releaseAlert);
}
As you can see the foo_init()
function requires two handles to functions from another module (bar). This allows those functions to be called in the case of an asychronous event. The bar module is mocked by Ceedling so that I can test for the use of those functions in some tests.
However, because the bar functions are mocked the setUp reports as a test fail everytime as the init function actually calls the bar_releaseAlert to ensure it's initial state.
"Function bar_releaseAlert. Called more times than expected."
I can add an "ignore" to the setup, as below, but it strikes me as wrong to have test type code in a set up or tear down. Maybe that assumption is wrong though?
void setUp(void)
{
bar_releaseAlert_Ignore();
s = foo_init(&bar_assertAlert, &bar_releaseAlert);
}
Or is this poor design on my part? How can I test a module that uses a mocked function where the setup calls that mocked function?