First you would separate functions out so they are testable to begin with.
A ball-of-mud main.c with everything in it doesn't lend itself to being tested.
Code:
// main.c
#include <stdio.h>
#include "add.h"
int main()
{
int a = 10;
int b = 2;
int result;
result = ADD ( a, b);
printf(" Result : %d", result);
return 0;
}
// add.h
#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED
int ADD ( int x, int y);
#endif
// add.c
#include "add.h"
int ADD ( int x, int y)
{
int r = x + y;
return r;
}
// add_test.c
#include <stdio.h>
#include <stdlib.h>
#include "add.h"
int main ( ) {
int result = EXIT_SUCCESS;
if ( ADD(1,2) != 3 ) {
fprintf(stderr,"Test ADD() failed\n");
result = EXIT_FAILURE;
}
return result;
}
In this tiny example, you compile the proper code with
gcc main.c add.c
And you compile and run the tests with
gcc add_test.c add.c && ./a.out
If you get no messages, your tests were successful.