ワンクリックで
ワンクリックで
| name | cpp-unit-testing |
| description | Instructions for creating unit tests for Smith |
This repo’s unit tests:
TEST, TEST_F, etc.).tests/ subdirectory.smith_add_tests(...).Place unit tests next to the component they cover:
src/smith/<component>/tests/ (recommended for library code)src/tests/ (project-wide smoke/regression tests)Each tests/ directory should contain:
*.cpp test filesCMakeLists.txt that registers those tests with smith_add_testsAlso ensure the parent component adds the tests subdirectory when tests are enabled:
if(SMITH_ENABLE_TESTS)
add_subdirectory(tests)
endif()
#include <gtest/gtest.h>TEST_F) when setup/teardown is shared.smith_add_testssmith_add_tests creates one test executable per source file and registers it with CTest.
The executable/test name is the source basename (e.g., test_state_manager.cpp → test_state_manager).
Minimal tests/CMakeLists.txt template:
set(my_component_test_depends
smith_my_component
gtest)
set(my_component_test_sources
test_feature_a.cpp
test_feature_b.cpp)
smith_add_tests(SOURCES ${my_component_test_sources}
DEPENDS_ON ${my_component_test_depends}
NUM_MPI_TASKS 1)
Notes:
DEPENDS_ON (the library under test + gtest + any required Smith/TPL targets).If a test requires MPI, add the MPI dependency and set NUM_MPI_TASKS:
smith_add_tests(SOURCES my_parallel_test.cpp
DEPENDS_ON gtest blt::mpi smith_my_component
NUM_MPI_TASKS 4)
If a test requires OpenMP, set NUM_OMP_THREADS accordingly.
If you need a CUDA-enabled unit test, gate it behind SMITH_ENABLE_CUDA and pass USE_CUDA:
if(SMITH_ENABLE_CUDA)
smith_add_tests(SOURCES my_cuda_test.cpp
DEPENDS_ON gtest smith_my_component
USE_CUDA TRUE)
endif()
-DENABLE_TESTS=ON -DSMITH_ENABLE_TESTS=ONctestctest -R test_state_managercmake/SmithMacros.cmakesrc/smith/physics/state/tests/CMakeLists.txtsrc/tests/CMakeLists.txt