The function add_first(int n) adds a number to a linked list and it returns 0 if successful and -1 if not.
The test is good but I would like to test a wider variety of situations so to test more of the same function with different parameters.
If I modify test_add_first and add a parameter it gives me an error because MY_RUN_TEST and RUN_TEST will only accept "myfunction(void)". Therefore I have to create individual functions for each number.
I have this code in my test.c file and I am using Unit testing - Unity as the title says.
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
ITEM *list = NULL;
void printList(struct ITEM *node)
{
if(node == NULL)
{
printf("list is empty");
}
while (node != NULL)
{
printf("%d ", node -> value);
node = node->next;
}
}
void test_add_first_1()
{
int ret;
ret = add_first(&list, 1);
TEST_ASSERT_EQUAL(0, ret);
}
void setUp(void)
{
// This is run before EACH test
}
void tearDown(void)
{
// This is run after EACH test
printList(list);
printf("\n");
}
int main (int argc, char * argv[])
{
UnityBegin();
MY_RUN_TEST(test_add_first_1);
return UnityEnd();
}
So my question to be more specific is there any way to test these as something like - MY_RUN_TEST(test_add_first(n)); - n being an integer?
If you find something else wrong at this piece of code please tell I am just starting with Unit Testing. :)
Thank you!