This repository is just a template for a shell (command line) application built using CMake, and using cpputest for unit test execution.
- Download all the files from this repository as a ZIP file and unzip them to your project base directory.
The main branch is populated with some example files. You may download a version without any examples from the unpopulated branch.
-
Edit the top level
CMakeLists.txt
and replace ProjectTemplate in the project command with your own project name (leave the .Top suffix). -
Put the headers for your private functions and classes and the implementation files in
app/sources/
. -
Edit
app/CMakeLists.txt
and replace ProjectTemplate in the project command with your own project name (this time without any suffix). This will be the base name for the executable file. You may also update your project version in the project command. -
Edit
app/CMakeLists.txt
and set the list of source and header files, and modify any other parameters that you like. -
Add your common mocks and expectation functions to
test/Mocks
. -
To create unit tests, copy the
test/TestTemplate/
directory to another directory undertest/
renaming it with the test name, then:- Rename the test implementation file
TestModule_test.cpp
according to your test module name (It's recommended to leave the _ test suffix). - Edit the test's
CMakeLists.txt
:- Replace ProjectTemplate and TestModule in the project command with your own project name and test module name (e.g. "YourProjectName.Test.YourTestModuleName").
- Set the list of production source files to be tested, and the list of test source files (test, mocks, other test helper functions, etc.).
- Edit the test implementation file to add your tests.
- Rename the test implementation file
-
Edit
test/CMakeLists.txt
and add all the subdirectories for your tests. -
Delete all example files and directories from the
test/
andapp/
directories. -
Replace
LICENSE.txt
with your project's license file. -
Create a build directory under the top directory (e.g.
build/
), and inside it executecmake .. G "<GeneratorOfYourChoice>"
(add any other configuration options that you like). -
Modify
appveyor.yml
(or delete it) according to your continouous integration needs.
OPTION | Description |
---|---|
-DCMAKE_BUILD_TYPE |
Selects build type (only for single-config generators) Debug Release (default)RelWithDebInfo (Release with debug info)MinSizeRel (Release with size optimization)Coverage (Debug with code coverage enabled) |
-DBUILD_TESTING |
Enables compilation and execution of testsON (default)OFF |
-DCPPUTEST_HOME |
Path to your CppUTest installation directory<filesystem path> |
-DLCOV_HOME |
Path to your LCOV installation directory<filesystem path> |
-DENABLE_INSTALLER |
Enables generation of installer packagesON (default)OFF |
-DCOVERAGE |
Enables code coverage in tests (only for multi-config generators) ON (default)OFF |
-DCOVERAGE_VERBOSE |
Enables verbose code coverageON OFF (default) |
-DCI_MODE |
Enables Continous Integration modeON OFF (default) |
- cmake (≥ v3.3, tested with v3.22.2)
- CppUTest [Optional, not needed if tests are disabled] (≥ v4.0, tested with v4.0-gdr0)
- On Windows:
- A C/C++ compiler, either:
- MinGW-w64 (tested with v7.3.0, v8.1.0, TDM-GCC v9.2.0 and TDM-GCC v10.3.0)
- Microsoft Visual Studio (tested with Visual Studio Community 2019 and 2022)
- LCOV for Windows [Optional, needed if tests and coverage are enabled using MinGW] (tested with v1.15.alpha1w)
- OpenCppCoverage [Optional, needed if tests and coverage are enabled using Visual Studio] (tested with v0.9.8.0)
- A C/C++ compiler, either:
- On Linux: