mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
3.2 KiB
3.2 KiB
C++ version of Gilded Rose refactoring kata
Introduction
The C++ version of the Gilded Rose refactoring kata is available in four variants using different test frameworks:
- Catch2 test framework
- Traditional unit test with the Catch2 test framework in the
test/cpp_catch2_unittestfolder. - Approval tests with the Catch2 test framework in the
test/cpp_catch2_approvaltestfolder.
- Traditional unit test with the Catch2 test framework in the
- GoogleTest framework
- Traditional unit test with the GoogleTest test framework in the
test/cpp_googletest_unittestfolder. - Approval tests with the GoogleTest test framework in the
test/cpp_googletest_approvaltestfolder.
- Traditional unit test with the GoogleTest test framework in the
The GildedRose.cc file, i.e. the code under test, is identical in all four variants.
Prerequisites
- CMake version ≥ 3.13
- C++ compiler that supports C++14
How to build and run tests in a terminal
Build tests
$ cd ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
The following test specific options for building with CMake are available.
BUILD_APPROVAL_TESTS_WITH_CATCH2:BOOL=ONThis option builds the approval tests with the Catch2 test framework.BUILD_UNIT_TESTS_WITH_CATCH2:BOOL=ONThis option builds the unit tests with the Catch2 test framework.BUILD_APPROVAL_TESTS_WITH_GTEST:BOOL=ONThis option builds the approval tests with the GoogleTest test framework.BUILD_UNIT_TESTS_WITH_GTEST:BOOL=ONThis option builds the unit tests with the GoogleTest test framework.
For example, run the CMake configuration cmake -DBUILD_APPROVAL_TESTS_WITH_CATCH2=OFF -DBUILD_UNIT_TESTS_WITH_CATCH2=OFF .. to disable the Catch2 based tests.
Show available tests
$ cd ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp/build
$ ctest -N
Test project ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp/build
Test #1: GildedRoseCatch2ApprovalTests
Test #2: GildedRoseCatch2UnitTests
Test #3: GildedRoseGoogletestApprovalTests
Test #4: GildedRoseGoogletestUnitTests
Run all tests
$ ctest
Run all tests with verbose output
$ ctest -VV
Run a specific test with verbose output
$ ctest -VV --tests-regex Catch2Approval
How to build and run tests using the CLion IDE
- Start CLion
- Select menu
File - Open... - Select folder
${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp - Select menu
Build - Build Project - Select menu
Run - Run... - Select what test variant to run, e.g.
GildedRoseCatch2ApprovalTests.
How to build and run tests using Visual Studio ≥ 2019
- Start Visual Studio
- Select
Open a local folder - Select folder
${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp - Wait for message
CMake generation finished.in the CMake output window at the bottom - Select what test variant to run in the drop down menu for Startup Items, e.g.
GildedRoseCatch2ApprovalTests.exe. - Select menu
Debug - Start