Google Test - 테스트 결과 레포트 만들기

반응형

 

Google Test : 테스트 결과 레포트 만들기

본 글에서는 Google Test 를 사용하여 수행한 단위테스트 결과를 레포트 형식으로 만드는 방법에 대해 설명한다.

 

테스트 결과 레포트를 만들기 위해서는 다음 단계를 거치면 된다.

  • 테스트 수행 시 "--gtest_output=xml:파일명" 옵션 사용 → XML 형식의 결과 파일 생성
  • 레포트 생성 툴을 이용하여 레포트 파일을 생성 → XML 형식의 결과 파일을 HTML 형식의 레포트 파일로 변환
  • 레포트 파일을 웹 브라우저에서 확인

본 글에서 사용된 환경은 다음과 같다. 

  • Ubuntu 16.04 리눅스
  • Google test : googletest-release-1.8.1
  • 레포트 생성 툴 : GTestReport 또는 gtest-report-prettify

 

1. 테스트 수행 시 "--gtest_output=xml:파일명" 옵션 사용

Google Test를 이용하여 테스트 수행 시에 "--gtest_ouput=xml:파일명" 옵션을 사용하면 다음과 같이 XML 형식의 결과 파일이 생성된다. 파일명을 result.xml로 명시하면 테스트 완료 후 "result.xml" 파일이 생성되는 것을 확인할 수 있다.

root@40d26a61c66a:/workspace/google-test-master/google-test-master# ./runSumTests --gtest_output=xml:result.xml
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SUM_TEST
[ RUN      ] SUM_TEST.SUM_TEST_1
[       OK ] SUM_TEST.SUM_TEST_1 (0 ms)
[----------] 1 test from SUM_TEST (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.
root@40d26a61c66a:/workspace/google-test-master/google-test-master#
root@40d26a61c66a:/workspace/google-test-master/google-test-master# ls
CMakeCache.txt  CMakeLists.txt  README.md            google-test  libsum.so  result.xml   test
CMakeFiles      Makefile        cmake_install.cmake  libsum       main.c     runSumTests
root@40d26a61c66a:/workspace/google-test-master/google-test-master#

 

 

결과 XML 파일을 편집기로 열어 보면 다음과 같은 내용이 포함되어 있다.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" timestamp="2020-05-30T03:35:04" time="0" name="AllTests">
  <testsuite name="SUM_TEST" tests="1" failures="0" disabled="0" errors="0" time="0">
    <testcase name="SUM_TEST_1" status="run" time="0" classname="SUM_TEST" />
  </testsuite>
</testsuites>

 

 

2. 레포트 생성 툴을 이용하여 레포트 파일 생성

레포트 생성툴은 XML 형식의 파일을 HTML 형식으로 변환해 주면 되므로 직접 만들 수도 있고 이미 만들어진 툴도 몇가지가 있어 보이는데, 본 글에서는 Github 검색 시 상위에 노출되는 툴 2가지를 사용해 본다.

 

 

2.1. GTestReport 툴을 이용하여 레포트 파일 생성

 

GTestReport는 아래 Github 저장소에서 다운로드할 수 있다. 

 

위 저장소에는 현재 Release 버전이 따로 없으므로 "Clone or download" 버튼을 클릭하여 압축파일을 다운로드한다.

 

다운로드한 압축파일의 압축을 해제하면 내부 구성이 다음과 같다.

root@40d26a61c66a:/workspace# cd gtest_report-master/
root@40d26a61c66a:/workspace/gtest_report-master#
root@40d26a61c66a:/workspace/gtest_report-master# ls -al
total 44
drwxrwxrwx 1 root root  4096 May 30 03:26 .
drwxrwxrwx 1 root root  4096 May 30 03:26 ..
-rwxr-xr-x 1 root root    37 Feb 25  2016 .gitignore
-rwxr-xr-x 1 root root   792 Feb 25  2016 README.md
-rwxr-xr-x 1 root root    90 Feb 25  2016 generate.cmd
-rwxr-xr-x 1 root root    89 Feb 25  2016 generate.sh
drwxrwxrwx 1 root root  4096 May 30 03:26 html_resources
drwxrwxrwx 1 root root     0 May 30 03:26 in
-rwxr-xr-x 1 root root 29305 Feb 25  2016 screenshot_of_html_report.png
drwxrwxrwx 1 root root     0 May 30 03:26 scripts
root@40d26a61c66a:/workspace/gtest_report-master#

 

 

1번 절차에서 생성된 XML 결과 파일을 in/ 디렉토리에 복사한 후 generate.sh 파일을 실행하면 out/ 디렉토리에 테스트 레포트인 hmtl 파일이 생성된다.

root@40d26a61c66a:/workspace/gtest_report-master# ls
README.md  generate.cmd  generate.sh  html_resources  in  screenshot_of_html_report.png  scripts
root@40d26a61c66a:/workspace/gtest_report-master#
root@40d26a61c66a:/workspace/gtest_report-master# cp ../google-test-master/google-test-master/result.xml in/
root@40d26a61c66a:/workspace/gtest_report-master#
root@40d26a61c66a:/workspace/gtest_report-master# ./generate.sh
Generate HTML report based on this reports: ['in/result.xml', 'in/test_a.xml', 'in/test_b.xml']
Output HTML report filename: out/gtest_report.html
root@40d26a61c66a:/workspace/gtest_report-master#
root@40d26a61c66a:/workspace/gtest_report-master#
root@40d26a61c66a:/workspace/gtest_report-master# ls out/
extraScript.js    gtest_report.html         gtest_report_notok.png  more_button.png
gtest_report.css  gtest_report_disable.png  gtest_report_ok.png
root@40d26a61c66a:/workspace/gtest_report-master#
root@40d26a61c66a:/workspace/gtest_report-master#

 

생성된 html 파일을 브라우저에서 열어 보면 다음과 같은 레포트를 확인할 수 있다.

아래 그림에서 붉은색 박스 부분이 위 1번 절차에서 생성된 result.xml 파일에 대한 결과 레포트이다. 그 외 test_a.xml과 test_b.xml은 GTestReport 에서 샘플로 제공하는 파일들에 대한 결과이다(해당 샘플 파일이 in/ 디렉토리에 포함되어 있다).

 

 

2.2. gtest-report-pretty 툴을 이용하여 레포트 파일 생성

 

gtest-report-pretty 는 아래 Github 저장소에서 다운로드할 수 있다. 

 

위 저장소에는 현재 Release 버전이 따로 없으므로 "Clone or download" 버튼을 클릭하여 압축파일을 다운로드한다.

 

다운로드한 압축파일의 압축을 해제하면 내부 구성이 다음과 같다.

root@40d26a61c66a:/workspace# cd gtest-report-prettify-master
root@40d26a61c66a:/workspace/gtest-report-prettify-master#
root@40d26a61c66a:/workspace/gtest-report-prettify-master# ls -al
total 298
drwxrwxrwx 1 root root   4096 May 30 05:51 .
drwxrwxrwx 1 root root   4096 May 30 05:39 ..
-rwxr-xr-x 1 root root    207 Jun 11  2019 README.md
-rwxr-xr-x 1 root root  22102 Jun 11  2019 gtest_example_output.html
-rwxr-xr-x 1 root root   3459 Jun 11  2019 gtest_parser.py
-rwxr-xr-x 1 root root 258918 Jun 11  2019 gtest_prettify_example.gif
-rwxr-xr-x 1 root root  10363 Jun 11  2019 gtest_template.html
root@40d26a61c66a:/workspace/gtest-report-prettify-master#

 

 

XML 결과 파일을 디렉토리 내에 복사한 후 다음 명령을 실행하면 동일 디렉토리에 테스트 레포트인 hmtl 파일이 생성된다.

python -m gtest_parser "파일명.xml"

 

다음은 1번 절차에서 생성된 result.xml에 대해 레포트 파일을 생성한 화면이다. "gtest_output.html"이라는 이름으로 생성되었다.

실행 중 "ImportError: No module named jinja2"라는 에러 메시지가 출력되면 "apt install python-jinja2" 명령으로 설치 후 재실행한다.
root@40d26a61c66a:/workspace/gtest-report-prettify-master# cp ../google-test-master/google-test-master/result.xml .
root@40d26a61c66a:/workspace/gtest-report-prettify-master#
root@40d26a61c66a:/workspace/gtest-report-prettify-master# python -m gtest_parser result.xml
[{'status': 'RUN', 'name': 'SUM_TEST_1', 'time': '0'}]
root@40d26a61c66a:/workspace/gtest-report-prettify-master#
root@40d26a61c66a:/workspace/gtest-report-prettify-master# ls -al
total 305
drwxrwxrwx 1 root root   4096 May 30 05:52 .
drwxrwxrwx 1 root root   4096 May 30 05:39 ..
-rwxr-xr-x 1 root root    207 Jun 11  2019 README.md
-rwxr-xr-x 1 root root  22102 Jun 11  2019 gtest_example_output.html
-rwxr-xr-x 1 root root   7117 May 30 05:52 gtest_output.html
-rwxr-xr-x 1 root root   3459 Jun 11  2019 gtest_parser.py
-rwxr-xr-x 1 root root 258918 Jun 11  2019 gtest_prettify_example.gif
-rwxr-xr-x 1 root root  10363 Jun 11  2019 gtest_template.html
-rwxr-xr-x 1 root root    349 May 30 05:52 result.xml
root@40d26a61c66a:/workspace/gtest-report-prettify-master#

 

생성된 html 파일을 브라우저에서 열어 보면 다음과 같은 레포트를 확인할 수 있다. 특이 기능으로는 표 별로 우측 상단의 각 탭을 클릭하면 원하는 항목(Passed, Failed, Disabled)만 필터링해 볼 수 있다.


 

파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음

'프로그래밍 > Google Test' 카테고리의 다른 글

Google test - tutorial (따라하기)  (1) 2020.12.31
Google test 설치하기  (0) 2020.12.31

댓글

Designed by JB FACTORY