Catch
A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch) (by catchorg)
Google Test
GoogleTest - Google Testing and Mocking Framework (by google)
Catch | Google Test | |
---|---|---|
57 | 71 | |
18,792 | 34,978 | |
0.8% | 0.8% | |
8.9 | 7.3 | |
19 days ago | 21 days ago | |
C++ | C++ | |
gtkbook License | BSD 3-clause "New" or "Revised" License |
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
Catch
Posts with mentions or reviews of Catch.
We have used some of these posts to build our list of alternatives
and similar projects. The last one was on 2024-10-17.
-
Unit Tests as Documentation
This is one area where a BDD style framework like catch2[0] really shines, IMO. The way tests are written in this style naturally lends itself to self-documenting each branch
[0]: https://github.com/catchorg/Catch2
-
Comparing C++ range libraries for filter+reverse case with non-trivial lambda
The code uses catch2 to test for correctness and performance. Catch2 is a unit testing framework for C++, but it also provides basic micro-benchmarking features. Unfortunately, it doesn't provide any way to visualise the results, so I created a script and submitted PR adding plotting capabilities to Catch.
- C++ Comparison Operator Craziness
-
How can I check the execution time of a program rendered in SFML?
https://github.com/catchorg/Catch2 (for unit testing, need to do timing yourself)
- Semi crise existentielle de développeur
-
`DestroyJavaVM()` failing on OpenJ9?
```c++ // https://github.com/catchorg/Catch2/tree/Catch1.x // https://github.com/philsquared/Catch/releases/download/v1.12.2/catch.hpp
-
How do you use the Catch testing library?
Include(FetchContent) FetchContent_Declare(Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.3.2 ) FetchContent_MakeAvailable(Catch2)
- Tracking the Fake GitHub Star Black Market
- The Little Things: Why you should always have benchmarks ready
-
Trying to add tests for my cmake for catch2 with ctest.
Another possible issue would be the include(Catch) in your root cmakelists.txt . To include Catch there it must be part of your module path. Otherwise you have to include the path to that catch2 cmake file. Here is that file in their repository - https://github.com/catchorg/Catch2/blob/devel/extras/Catch.cmake . I recon that CMake doesn't know about this file since you call find_package(Catch2 REQUIRED) later in your subdirectory
Google Test
Posts with mentions or reviews of Google Test.
We have used some of these posts to build our list of alternatives
and similar projects. The last one was on 2024-11-24.
-
The Two Factions of C++
> Googletest ... declares a direct dependency on an older LTS release of absl
Looking at the build configuration code:
https://github.com/google/googletest/blob/main/CMakeLists.tx...
it seems like the dependence on Abseil is optional. i.e. you can use googltest on its own. I wouldn't recommend it (I kinda like doctest), but still.
-
Getting started with GoogleTest and CMake
include(FetchContent) # Fetch GoogleTest FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.11.0 ) FetchContent_MakeAvailable(googletest) # Collect C++ source files recursively file(GLOB_RECURSE CXX_FILES "${CMAKE_CURRENT_LIST_DIR}/*.cpp") add_executable(unit_tests ${CXX_FILES}) # Link GoogleTest libraries target_link_libraries(unit_tests PRIVATE gtest_main ${PROJECT_NAME}_lib # Link to the main project library ) # Include directories (including where GoogleTest is built) target_include_directories(unit_tests PRIVATE ${gtest_SOURCE_DIR}/include) # Add include directories for tests to find headers target_include_directories(unit_tests PRIVATE ${PROJECT_SOURCE_DIR}/src) # Enable testing and discover tests # Discover and run tests include(GoogleTest) gtest_discover_tests(unit_tests)
-
Open Source C++ Stack
Google Test
-
Creating k-NN with C++ (from Scratch)
cmake_minimum_required(VERSION 3.5) project(knn_cpp CXX) include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.11.0 ) FetchContent_MakeAvailable(googletest) FetchContent_Declare(matplotplusplus GIT_REPOSITORY https://github.com/alandefreitas/matplotplusplus GIT_TAG origin/master) FetchContent_GetProperties(matplotplusplus) if(NOT matplotplusplus_POPULATED) FetchContent_Populate(matplotplusplus) add_subdirectory(${matplotplusplus_SOURCE_DIR} ${matplotplusplus_BINARY_DIR} EXCLUDE_FROM_ALL) endif() function(knn_cpp_test TEST_NAME TEST_SOURCE) add_executable(${TEST_NAME} ${TEST_SOURCE}) target_link_libraries(${TEST_NAME} PUBLIC matplot) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../lib LIB_SOURCES) target_link_libraries(${TEST_NAME} PRIVATE gtest gtest_main gmock gmock_main) target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../) target_sources(${TEST_NAME} PRIVATE ${LIB_SOURCES} ) include(GoogleTest) gtest_discover_tests(${TEST_NAME}) endfunction() knn_cpp_test(LinearAlgebraTest la_test.cc) knn_cpp_test(KnnTest knn_test.cc) knn_cpp_test(UtilsTest utils_test.cc)
-
Starting with C
Okay, time to start unit tests!!! We will use Unity Test Framework to do unit testing. It is one of widely used testing frameworks alongside with Check, Google Test etc. Just downloading source code, and putting it to the project folder is enough to make it work (that is also why it is portable).
-
Just in case: Debian Bookworm comes with a buggy GCC
Updating GCC (it happened to GoogleTest).
-
Automatically run tests, formatters & linters with CI!
Roy's project uses Google Test, a C++ testing framework. His testing setup is similar to mine as we both keep source files in one directory and tests in another. The key difference is that I can run the tests using the Visual Studios run button. It was fairly easy to write the new tests as there were existing ones that I could reference to check the syntax!
-
C++ Unit Testing Using Google Test - My Experience
The Google Test Documentation provides a primer for first-time users. The primer introduces some basic concepts and terminology, some of which I've been able to learn for this lab exercise.
-
Basic C++ Unit Testing with GTest, CMake, and Submodules
> git submodule add https://github.com/google/googletest.git > git submodule update --init --recursive
-
VS code + cmake + gtest?
cmake_minimum_required(VERSION 3.14) project(my_project) # GoogleTest requires at least C++14 set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) enable_testing() add_executable( hello_test hello_test.cpp ) target_link_libraries( hello_test GTest::gtest_main ) include(GoogleTest) gtest_discover_tests(hello_test)
What are some alternatives?
When comparing Catch and Google Test you can also consider the following projects:
doctest - The fastest feature-rich C++11/14/17/20/23 single-header testing framework
Boost.Test - The reference C++ unit testing framework (TDD, xUnit, C++03/11/14/17)
CppUTest - CppUTest unit testing and mocking framework for C/C++
CppUnit - C++ port of JUnit
Google Mock
Unity Test API - Simple Unit Testing for C
benchmark - A microbenchmark support library