Frameworks para C 3º DeSif
-
Upload
gleison-rodrigues -
Category
Documents
-
view
509 -
download
4
Transcript of Frameworks para C 3º DeSif
3º Encontro DeSif
FrameWork de teste para C/C++
● Check: A unit testing framework for C.
● MinUnit: TDD em C, simples e prático.
● Googletest: Google C++ Testing Framework.
● Cgreen: A unit tester for the C software developer.
3º Encontro DeSif
Check● Versão 0.9.8
● Ultima atualização 23-09-2009
● Hospedado no sourceforge
● Faz uso de macros:
● Escrevendo um teste:
3º Encontro DeSif
#include <check.h>
START_TEST (test_name){ /* unit test code */}END_TEST
3º Encontro DeSif
MinUnit● Realmente minimalista:
apenas um aquivo MinUnit.h
● Pagina de referencia Jera.
● Escrevendo um teste:
3º Encontro DeSif #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; }
3º Encontro DeSif
/* continuação */
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;
}
3º Encontro DeSif
GoogleTest● Desenvolvido para C++
● Versão 1.6.0
● Hospedado no GoogleCode.
● Faz uso de macros.
3º Encontro DeSif #include <limits.h> #include "sample1.h" #include "gtest/gtest.h"
// Tests Factorial().
TEST(FactorialTest, Negative) { EXPECT_EQ(1, Factorial(-5)); EXPECT_TRUE(Factorial(-10) > 0);}
TEST(FactorialTest, Zero) { EXPECT_EQ(1, Factorial(0));}
TEST(FactorialTest, Positive) { EXPECT_EQ(1, Factorial(1)); EXPECT_EQ(2, Factorial(2)); EXPECT_EQ(40320, Factorial(8));}
3º Encontro DeSif
Cgreen● Note that this tool is for C programming, not C++.
● Tem um guia em português do Brasil
● Versão 1.0.0-beta2
● Hospedado no sourceforge
● Faz uso de macros
3º Encontro DeSif#include "cgreen/cgreen.h"
void this_test_should_pass() {assert_true(1);
}
void this_test_should_fail() {assert_true(0);
}
int main(int argc, char **argv) {TestSuite *suite = create_test_suite();
add_test(suite, this_test_should_pass);add_test(suite, this_test_should_fail);
return run_test_suite(suite, create_text_reporter());}
3º Encontro DeSif
Dúvidas???
3º Encontro DeSif