среда, 24 апреля 2013 г.

Самый маленький фреймворк для Unit тестирования проектов на Си

Существует такой фреймворк для unit-тестирования MinUnit который очень удобно встраивать в ПО микроконтроллеров, по причине его экстремально малого размера и отсутствия операций выделения памяти.








Вот он:

#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;


Небольшой пример с странице фреймворка:


#include <stdio.h>
#include "minunit.h"
 
int tests_run = 0;
 
int foo = 7;
int bar = 4;
 
static char * test_foo() {
    mu_assert("error, foo != 7", foo == 7);
    return 0;
}
 
static char * test_bar() {
    mu_assert("error, bar != 5", bar == 5);
    return 0;
}
 
static char * all_tests() {
    mu_run_test(test_foo);
    mu_run_test(test_bar);
    return 0;
}
 
int main(int argc, char **argv) {
    char *result = all_tests();
    if (result != 0) {
        printf("%sn", result);
    }
    else {
        printf("ALL TESTS PASSEDn");
    }
    printf("Tests run: %dn", tests_run);
 
    return result != 0;
}


Страница MinUnit.

Комментариев нет:

Отправить комментарий