Его первое тестирование программ C. У меня есть этот файл заголовок, который я хотел бы проверить:CUnit Tests get Build Error
#ifndef CALCULATOR_HELPER_H
#define CALCULATOR_HELPER_H
#endif
int add(int num1, int num2) {
return num1 + num2;
}
Я использую рамки Кунит, чтобы проверить его. Я использую Netbeans как IDE. Ниже приведен код.
#include <stdio.h>
#include <stdlib.h>
#include "CUnit/Basic.h"
#include "calculator_helper.h"
/*
* CUnit Test Suite
*/
int init_suite(void) {
return 0;
}
int clean_suite(void) {
return 0;
}
/* IMPORTANT PART: */
void testAdd() {
int num1 = 2;
int num2 = 2;
int result = add(num1, num2);
if (result == 4) {
CU_ASSERT(0);
}
}
int main() {
CU_pSuite pSuite = NULL;
/* Initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
/* Add a suite to the registry */
pSuite = CU_add_suite("newcunittest", init_suite, clean_suite);
if (NULL == pSuite) {
CU_cleanup_registry();
return CU_get_error();
}
/* Add the tests to the suite */
if ((NULL == CU_add_test(pSuite, "testAdd", testAdd))) {
CU_cleanup_registry();
return CU_get_error();
}
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}
ПРОБЛЕМА
Когда я строю тест, я получаю Скопление ИСПЫТАНИЯ FAILED. В частности, я получаю следующее:
In function `add': NetBeans/Calculator/calculator_helper.h:12: multiple definition of `add' build/Debug/GNU-Linux-x86/tests/tests/newcunittest.o:NetBeans/Calculator/./calculator_helper.h:12: first defined here collect2: error: ld returned 1 exit status
Может кто-нибудь сказать мне, почему я получаю эту ошибку. Я пробовал искать в Google, но мне не повезло.
Спасибо. Его работа сейчас :) – Goaler444