Unit Testing: CUnit

1.1k Views Asked by At

This one is causing grief; I'd like to get to grips with CUnit.

Have installed it using the following instructions: http://macappstore.org/cunit/

I am using the following at command line: gcc myprog.c -Wall -Wfloat-equal -Wextra -O2 -pedantic -ansi -lm -lcunit -o myprog

It compiles without errors and i proceed with the following: ./myprog

I have the following sitting inside my code:

#include <stdio.h>
#include <math.h>
#include <CUnit/CUnit.h>

int maxi(int i1, int i2);
void test_maxi(void);
struct code{
   char words[5][5];
   int cnt; /* Current Word Counter*/
};
typedef struct code Code;

int main(void){
  test_maxi();   

   return 0;
}

int maxi(int i1, int i2){
   return (i1 > i2) ? i1 : i2;
}

void test_maxi(void){
   CU_ASSERT(maxi(0,2) == 2);
   CU_ASSERT(maxi(0,-2) == 0);
   CU_ASSERT(maxi(2,2) == 2);
}

My assumption is that this should generate some kind of .txt or alternative file within the same directory. Is this assumption incorrect? What should i be looking for instead?

Update: I am currently getting the following on command line; "Assertion failed: (NULL != f_pCurSuite), function CU_assertImplementation, file TestRun.c, line 162. Abort trap: 6"

(Full Disclosure: New to programming....so be gentle :P )

1

There are 1 best solutions below

0
On

You're not calling test_maxi in main() so it just exists as a function, but it is not being run. You need to run it in main. – Eli Sadoff

You need to create a test suite as explained here. – pbn