-
Notifications
You must be signed in to change notification settings - Fork 0
[Portuguese] METRIC_TEST
Luiz Felipe edited this page Aug 21, 2021
·
3 revisions
METRIC_TEST(test_name);
METRIC_TEST_END();
METRIC_TEST_FAIL(message);
METRIC_TEST_OK(message);
METRIC_TEST
executa uma função de teste e imprime o status no final. Uma função de teste retorna o seu status, e os macros METRIC_TEST_FAIL
e METRIC_TEST_OK
podem ser usados para definir este status. A execução destes macros faz a função parar a execução.
O macro METRIC_TEST_END
pode ser usado no final de todos os testes para mostrar status de testes bem sucedidos e testes falhados. Esse macro retorna da main o número de testes que falharam.
Uma função de teste deve ter o tipo de retorno test_t
e não ter parâmetros.
#include <stdio.h>
#include "metric.h"
test_t test_go_fail(void)
{
volatile int x = 3;
if (x < 5) {
METRIC_TEST_FAIL("x é menor que 5");
}
METRIC_TEST_OK("x é o maior \\o/");
}
test_t test_go_success(void)
{
volatile int x = 9;
if (x < 5) {
METRIC_TEST_FAIL("x é menor que 5");
}
METRIC_TEST_OK("x é o maior \\o/");
}
int main(void)
{
METRIC_TEST(test_go_fail);
METRIC_TEST(test_go_success);
METRIC_TEST_END();
}
Saída:
<TEST> tst.c:28: test_go_fail
[FAIL] x é menor que 5
<TEST> tst.c:29: test_go_success
[ OK ] x é o maior \o/
Tests: 2 | Failures: 1 | Successes: 1