A dockerized C++ template for running unit tests with CMake and GoogleTest testing framework.
├── CMakeLists.txt # Project configuration
├── include/ # Public headers
│ └── Calculator.h # Example class declaration
├── src/ # Source files
│ ├── main.cpp # Entry point
│ └── Calculator.cpp # Example class implementation
├── tests/ # Unit tests
| ├── test_main.cpp # Test runner
| └── test_calculator.cpp # Tests for Calculator
├── Dockerfile # Docker configuration
├── build_docker.sh # Docker build script
├── run_tests.sh # Test execution script
└── README.md # This file
- C++ 17 with CMake build system
- GoogleTest testing framework for unit testing
- Docker support for containerized testing
-
Build the Docker image:
./build_docker.sh [image-name] [platform]
Examples:
./build_docker.sh # Uses default: cpp-unit-tests-base ./build_docker.sh my-cpp-app # Custom image name
-
Run tests in Docker:
./build_docker.sh my-cpp-app docker run --rm -it my-cpp-app ./run_tests.sh
-
Interactive Docker session:
docker run -it --rm cpp-unit-tests-base bash # or you can mount your local folder in docker docker run -it --rm -v $(pwd):/app cpp-unit-tests-base bash
Inside the container, you can run:
./run_tests.sh # run the build and tests valgrind --leak-check=full ./build/basic_app # check for memory leaks ./build/cpp_unit_tests # run the test binary for more output
This is a Template - Replace with Your Code!
This template provides the essential structure and configuration files for a C++ project with unit testing. You should replace the example code with your own C++ application while maintaining the project structure.
Keep these key files and structure for your project:
include/
- Your header filessrc/
- Your main application codetests/
- Your unit testsCMakeLists.txt
- CMake configuration (update for your project details)Dockerfile
- Docker configuration for containerized testing. LEAVE AS IS.build_docker.sh
- Docker build script. LEAVE AS ISrun_tests.sh
- Test execution script. LEAVE AS IS.