# Minunit

# FAQ

# How to install minunit?

Minunit is really simple to install, is only 5 lines of codes:

/* file: minunit.h */
#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
#define mu_run_test(test) do { char *message = test(); tests_run++; \
                               if (message) return message; } while (0)
extern int tests_run;

# How to create test unit?

// 1. create variable containing passed tests
int tests_run = 0;

// 2. create our test functions
static char * test_foo() {
    mu_assert("error, foo != 7", foo == 7);
    return 0;
}
 

// 3. create a function containing all our test
static char * all_tests() {
   mu_run_test(test_foo);
   mu_run_test(test_bar);
   return 0;
}

// 4. finally run it in our main function
int main(int argc, char **argv) {
    char *result = all_tests();
    if (result != 0) {
        printf("%s\n", result);
    }
    else {
        printf("ALL TESTS PASSED\n");
    }
    printf("Tests run: %d\n", tests_run);
    return result != 0;
}

# References and Resources

  • http://www.jera.com/techinfo/jtns/jtn002.html
  • https://github.com/siu/minunit