Refactor C++ version of the Gilded Rose kata

* Make it possible to build and run tests in CLion
  and Visual Studio 2019 out of the box

* Provide four types of initial test using different test frameworks:
  * Catch2 test framework
    * Traditional unit testing using Catch2
    * Approval test using Catch2
  * Google Test test framework
    * Traditional unit testing using Google Test
    * Approval test using Google Test

* The different types of initial test are located in separate folders
  in the test folder.

* Remove scripts to build and run tests and replace
  with instructions in the cpp README.md

* Use C++17

* Use CMake => 3.13
This commit is contained in:
Jacob Mossberg committed 2019-12-09 08:40:47 +01:00
1 parent 16dd174765
commit 1836cca836
30 files changed
+20786 -287

No files matched your search

+55 -25
View File
@@ -1,38 +1,68 @@
TL;DR;
-------
run-once.sh runs your tests once
# C++ version of Gilded Rose refactoring kata
Before this will work you will need:
- make and a C++ compiler (like gcc) is installed on your system and is in the PATH
- The GTest framework in the directory gtest.
- If your IDE does the compilation and linking, you should remove the first 3 lines
in the run-once.sh file.
## Introduction
The C++ version of the Gilded Rose refactoring kata is available in four variants using different test frameworks:
More Verbose Instructions
-------------------------
* Catch2 test framework
1. Traditional unit test with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_unittest` folder.
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_approvaltest` folder.
* Google Test framework
1. Traditional unit test with the [Googletest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_unittest` folder.
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [Googletest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_approvaltest` folder.
Create a clone of both GildedRose-Refactoring-Kata and googletest in a directory we'll call ${ROOT_INSTALL_DIR}:
The `GildedRose.cc` file, i.e. the code under test, is identical in all four variants.
cd ${ROOT_INSTALL_DIR}
git clone https://github.com/emilybache/GildedRose-Refactoring-Kata
git clone https://github.com/google/googletest
## Prerequisites
Make googletest by running make in subfolder googletest/googletest/make:
* CMake version >= 3.13
* C++ compiler that support C++17
cd googletest/googletest/make
make
## How to build and run tests in a terminal
Create a softlink in the GildedRose-Refactoring-Kata clone pointing at the googletest code:
### Build tests
cd ${ROOT_INSTALL_DIR}/GildedRose-Refactoring-Kata/cpp
ln -s ${ROOT_INSTALL_DIR}/googletest/googletest gtest
$ cd ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
Make the GildedRose-Refactoring-Kata:
### Show available tests
make
$ 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
Then you should be able to run the tests:
### Run all tests
./run_once.sh
$ ctest
If you have been successful, then you should see a failing test, "GildedRoseTest.Foo".
### 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](https://www.jetbrains.com/clion/)
1. Start CLion
2. Select menu `File - Open...`
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
4. Select menu `Build - Build Project`
4. Select menu `Run - Run...`
4. Select what test variant to run, e.g. `GildedRoseCatch2ApprovalTests`.
## How to build and run tests using Visual Studio 2019
1. Start Visual Studio 2019
2. Select `Open a local folder`
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
4. Wait for message `CMake generation finished.` in the CMake output window at the bottom
5. Select what test variant to run in the drop down menu for Startup Items, e.g. `GildedRoseCatch2ApprovalTests.exe`.
6. Select menu `Debug - Start`