CUTE is an easy to use C++ unit testing framework that leverages modern C++ libraries and features. CLion is a cross-platform IDE for C and C++ made by JetBrains. CUTE has, currently, an Eclipse plugin that is easy to install and use. This simple project aims to help beginners run CUTE tests in CLion.
You can either clone this repository (using git clone
) or copy the structure represented below.
Be sure to check the .gitignore file in order to keep unwanted (and possibly conflituous) files from being pushed to a Git repository.
The following tutorial was made and test with the following software:
- CLion 2017.2.2 #CL-172.3968.17
- CUTE Standalone v2.0.0
If something goes wrong or is hard to understand, be sure to contact us at ni@aefeup.pt, message us on Facebook or submit a pull request here!
For this to work, we need to install the following programs:
This step is not needed if you cloned the repository. Otherwise, you need to create the following structure:
cute-clion
|-- CMakeLists.txt # compilation instructions
`-- src # source code directory/folder
`-- Test.cpp
Now, you must add the CUTE library to the project. Just extract the download file to your project directory, alongside the src/
folder.
The structure should look like this afterwards:
cute-clion
|-- CMakeLists.txt
|-- cute_lib # added folder
| |-- ... (omitted files)
`-- src
`-- Test.cpp
After having achieved the structure above, we need to tell CLion to use cute_lib
to add CUTE functions to its suggestions system.
To do that, on 'Project' file explorer, right-click the cute_lib folder and mark the directory as 'Library Files', as seen below.
- More folders can be created inside the
src
directory since they are all included automatically. - The
Test.cpp
file can be deleted and changed, it is just an example. However, it is mandatory that there is a.cpp
file with amain
function.
CLion uses CMake to compile its programs. As you can probably guess, CMakeLists.txt
is the file that tells CMake how to compile the source code.
Let's take a closer look.
1 cmake_minimum_required(VERSION 3.8)
2 project(clion)
3 include_directories(cute_lib)
4 file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
5 add_executable(clion ${SOURCE_FILES})
Explanation:
- This instruction specifies the minimum version of CMake required;
- The
project
command names the project (to be used later); - This line includes the CUTE library in the compilation process, allowing us to use its functionality;
- The
file
instruction will get all filenames that match thesrc/*.cpp
pattern and join them all in theSOURCE_FILES
variable; - This function creates the executable from the project name provided in the second line and all the files in the
SOURCE_FILES
variable.