Some example of criterion unit tests
- Installation
- Example
- Rules for Makefile
- Some example of unit test with criterion
Use this file to install criterion
chmod 777 install_criterion.sh
./install_criterion.sh
tests_run:
gcc $(SRCS) tests/*.c -o unit_tests --coverage -lcriterion -Iincludes/
- ./unit_tests
Unit test which test output of a program
#include <criterion/criterion.h>
#include <criterion/redirect.h>
static void redirect_all_stdout(void)
{
cr_redirect_stdout();
cr_redirect_stderr();
}
Test(test_output, test_output_string, .init=redirect_all_stdout)
{
write(1, "test output\n", 13);
cr_assert_stdout_eq_str("test output\n");
}
Unit test which test string output of a function
#include <criterion/criterion.h>
Test(test_string_compare, test_string)
{
char test[] = "test string";
cr_assert_str_eq(test, "test string");
}