프로그램 사용/cunit2021. 4. 6. 11:31

테스트에 따른 include 파일

#include <CUnit/Automated.h>
void         CU_automated_run_tests(void)

#include <CUnit/Basic.h>
CU_ErrorCode    CU_basic_run_tests(void)

#include <CUnit/Console.h>
void CU_console_run_tests(void)

#include <CUnit/CUCurses.h>
void CU_curses_run_tests(void)

[링크 : http://cunit.sourceforge.net/doc/running_tests.html]

[링크 : https://sharpis0826.blogspot.com/2013/11/cunit-cunit_17.html]

 

ncurse로 멋지게 나오는걸 기대했는데 현실은 에러! 빌드도 안됨 ㅋ

/usr/bin/ld: /tmp/ccIbfUYB.o: in function `main':
cunit.c:(.text+0x314): undefined reference to `CU_curses_run_tests'
collect2: error: ld returned 1 exit status

 

아무튼.. ncurse는 다른 패키지로 분리되어 있고.. include도 다른걸로 해주어야 하니 급 귀찮..

$ apt-cache search cunit
libcunit1 - Unit Testing Library for C
libcunit1-dev - Unit Testing Library for C -- development files
libcunit1-doc - Unit Testing Library for C -- documentation
libcunit1-ncurses - Unit Testing Library for C (ncurses)
libcunit1-ncurses-dev - Unit Testing Library for C (ncurses) -- development files

 

CU_basic_run_tests()

결과를 화면으로 출력함

$ ./a.out


     CUnit - A unit testing framework for C - Version 2.1-3
     http://cunit.sourceforge.net/


Suite: Suite_1
  Test: test of fprintf() ...passed
  Test: test of fread() ...passed

Run Summary:    Type  Total    Ran Passed Failed Inactive
              suites      1      1    n/a      0        0
               tests      2      2      2      0        0
             asserts      5      5      5      0      n/a

Elapsed time =    0.001 seconds

 

CU_automated_run_tests()

결과를 XML로 출력함

$ ls -al
합계 36
drwxrwxr-x  2 minimonk minimonk  4096  4월  6 11:37 .
drwxrwxr-x 13 minimonk minimonk  4096  4월  6 11:01 ..
-rwxrwxr-x  1 minimonk minimonk 17488  4월  6 11:37 a.out
-rw-rw-r--  1 minimonk minimonk  3734  4월  6 11:37 cunit.c
-rw-rw-r--  1 minimonk minimonk     9  4월  6 11:37 temp.txt

$ ./a.out

$ ls -al
합계 40
drwxrwxr-x  2 minimonk minimonk  4096  4월  6 11:37 ./
drwxrwxr-x 13 minimonk minimonk  4096  4월  6 11:01 ../
-rw-rw-r--  1 minimonk minimonk  1670  4월  6 11:37 CUnitAutomated-Results.xml
-rwxrwxr-x  1 minimonk minimonk 17488  4월  6 11:37 a.out*
-rw-rw-r--  1 minimonk minimonk  3734  4월  6 11:37 cunit.c
-rw-rw-r--  1 minimonk minimonk     9  4월  6 11:37 temp.txt

$ cat CUnitAutomated-Results.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="CUnit-Run.xsl" ?>
<!DOCTYPE CUNIT_TEST_RUN_REPORT SYSTEM "CUnit-Run.dtd">
<CUNIT_TEST_RUN_REPORT>
  <CUNIT_HEADER/>
  <CUNIT_RESULT_LISTING>
    <CUNIT_RUN_SUITE>
      <CUNIT_RUN_SUITE_SUCCESS>
        <SUITE_NAME> Suite_1 </SUITE_NAME>
        <CUNIT_RUN_TEST_RECORD>
          <CUNIT_RUN_TEST_SUCCESS>
            <TEST_NAME> test of fprintf() </TEST_NAME>
          </CUNIT_RUN_TEST_SUCCESS>
        </CUNIT_RUN_TEST_RECORD>
        <CUNIT_RUN_TEST_RECORD>
          <CUNIT_RUN_TEST_SUCCESS>
            <TEST_NAME> test of fread() </TEST_NAME>
          </CUNIT_RUN_TEST_SUCCESS>
        </CUNIT_RUN_TEST_RECORD>
      </CUNIT_RUN_SUITE_SUCCESS>
    </CUNIT_RUN_SUITE>
  </CUNIT_RESULT_LISTING>
  <CUNIT_RUN_SUMMARY>
    <CUNIT_RUN_SUMMARY_RECORD>
      <TYPE> Suites </TYPE>
      <TOTAL> 1 </TOTAL>
      <RUN> 1 </RUN>
      <SUCCEEDED> - NA - </SUCCEEDED>
      <FAILED> 0 </FAILED>
      <INACTIVE> 0 </INACTIVE>
    </CUNIT_RUN_SUMMARY_RECORD>
    <CUNIT_RUN_SUMMARY_RECORD>
      <TYPE> Test Cases </TYPE>
      <TOTAL> 2 </TOTAL>
      <RUN> 2 </RUN>
      <SUCCEEDED> 2 </SUCCEEDED>
      <FAILED> 0 </FAILED>
      <INACTIVE> 0 </INACTIVE>
    </CUNIT_RUN_SUMMARY_RECORD>
    <CUNIT_RUN_SUMMARY_RECORD>
      <TYPE> Assertions </TYPE>
      <TOTAL> 5 </TOTAL>
      <RUN> 5 </RUN>
      <SUCCEEDED> 5 </SUCCEEDED>
      <FAILED> 0 </FAILED>
      <INACTIVE> n/a </INACTIVE>
    </CUNIT_RUN_SUMMARY_RECORD>
  </CUNIT_RUN_SUMMARY>
  <CUNIT_FOOTER> File Generated By CUnit v2.1-3 - Tue Apr  6 11:37:15 2021
 </CUNIT_FOOTER>
</CUNIT_TEST_RUN_REPORT>

 

CU_console_run_tests()

R 누르면 CU_basic_run_tests()와 차이는 없지만 테스트 항목을 하나하나 on/off 가능하다.

$ ./a.out


     CUnit - A Unit testing framework for C - Version 2.1-3
             http://cunit.sourceforge.net/


***************** CUNIT CONSOLE - MAIN MENU ******************************
(R)un  (S)elect  (L)ist  (A)ctivate  (F)ailures  (O)ptions  (H)elp  (Q)uit
Enter command: S

--------------------- Registered Suites -----------------------------
 #  Suite Name                         Init? Cleanup? #Tests Active?

 1. Suite_1                             Yes      Yes      2     Yes
---------------------------------------------------------------------
Total Number of Suites : 1

Enter number of suite to select (1-1) : 1
Suite 'Suite_1' selected.

***************** CUNIT CONSOLE - SUITE MENU ***************************
(R)un (S)elect (L)ist (A)ctivate (F)ailures (U)p (O)ptions (H)elp (Q)uit
Enter command: L

----------------- Test List ------------------------------
Suite: Suite_1

 #  Test Name                          Active?

 1. test of fprintf()                     Yes
 2. test of fread()                       Yes
----------------------------------------------------------
Total Number of Tests : 2

***************** CUNIT CONSOLE - SUITE MENU ***************************
(R)un (S)elect (L)ist (A)ctivate (F)ailures (U)p (O)ptions (H)elp (Q)uit
Enter command: R

Running Suite : Suite_1
     Running Test : test of fprintf()
     Running Test : test of fread()

Run Summary:    Type  Total    Ran Passed Failed Inactive
              suites      1      1    n/a      0        0
               tests      2      2      2      0        0
             asserts      5      5      5      0      n/a

Elapsed time =    0.001 seconds

 

CU_curses_run_tests();

CU_console_run_tests의 ncurse 버전

               CUnit - A Unit testing framework for C - Version 2.1-3
                            http://cunit.sourceforge.net/

 Progress

 Tests Run :      0   Success :      0   Failed :      0

┌───────────────────────────────── Details Window ──────────────────────────────────┐
│Welcome to CUnit.  Press the indicated key to run the command.                     │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
│                                                                                   │
└───────────────────────────────────────────────────────────────────────────────────┘
 (R)un  (S)elect  (L)ist  (A)ctivate  (F)ailures  (O)ptions  (H)elp  (Q)uit

'프로그램 사용 > cunit' 카테고리의 다른 글

ubuntu에서 cunit  (0) 2021.04.06
CI/CD - Continuous integration continuous delivery  (0) 2021.04.05
cunit  (0) 2021.04.05
CUnit  (0) 2014.03.11
Posted by 구차니