en un clic
cpp-unit-testing
Instructions for creating unit tests for Axom
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Menu
Instructions for creating unit tests for Axom
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Basé sur la classification professionnelle SOC
| name | cpp-unit-testing |
| description | Instructions for creating unit tests for Axom |
This repo’s unit tests:
TEST, TEST_F, etc.).tests/ subdirectory.axom_add_test(...).Place unit tests next to the component they cover:
src/axom/<component>/tests/ (recommended for library code)src/thirdparty/tests/ (third-party smoke tests)Each tests/ directory should contain:
*.cpp test filesCMakeLists.txt that builds test executables with axom_add_executable and registers them with axom_add_testAlso ensure the parent component adds the tests subdirectory when tests are enabled:
if(AXOM_ENABLE_TESTS)
add_subdirectory(tests)
endif()
#include <gtest/gtest.h>TEST_F) when setup/teardown is shared.axom_add_testAxom tests typically create one test executable per source file with axom_add_executable, then register it with CTest using axom_add_test.
The executable name usually appends _test; the CTest name usually omits that suffix.
Minimal tests/CMakeLists.txt template:
set(my_component_test_depends
my_component
gtest)
set(my_component_test_sources
feature_a.cpp
feature_b.cpp)
foreach(test ${my_component_test_sources})
get_filename_component(test_name ${test} NAME_WE)
axom_add_executable(NAME ${test_name}_test
SOURCES ${test}
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
DEPENDS_ON ${my_component_test_depends}
FOLDER axom/my_component/tests)
axom_add_test(NAME ${test_name}
COMMAND ${test_name}_test)
endforeach()
Notes:
DEPENDS_ON (the library under test + gtest + any required Axom/TPL targets).If a test requires MPI, add the MPI dependency and set NUM_MPI_TASKS:
axom_add_executable(NAME my_parallel_test
SOURCES my_parallel_test.cpp
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
DEPENDS_ON gtest blt::mpi my_component
FOLDER axom/my_component/tests)
axom_add_test(NAME my_parallel
COMMAND my_parallel_test
NUM_MPI_TASKS 4)
If a test requires OpenMP, set NUM_OMP_THREADS accordingly.
If you need a CUDA- or HIP-enabled unit test, gate it behind the matching Axom option and add the matching BLT GPU dependency:
AXOM_ENABLE_CUDA with blt::cuda for CUDA-compiled sources, or the CUDA runtime target when only runtime API linkage is needed.AXOM_ENABLE_HIP with blt::hip.if(AXOM_ENABLE_HIP)
axom_add_executable(NAME my_hip_test
SOURCES my_hip_test.cpp
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
DEPENDS_ON gtest blt::hip my_component
FOLDER axom/my_component/tests)
axom_add_test(NAME my_hip
COMMAND my_hip_test)
endif()
Use the same shape for CUDA tests:
if(AXOM_ENABLE_CUDA)
axom_add_executable(NAME my_cuda_test
SOURCES my_cuda_test.cpp
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
DEPENDS_ON gtest blt::cuda my_component
FOLDER axom/my_component/tests)
axom_add_test(NAME my_cuda
COMMAND my_cuda_test)
endif()
For tests that are always built but need GPU linkage in GPU builds, append the dependency conditionally before creating the target:
set(my_component_test_depends
my_component
gtest)
blt_list_append(TO my_component_test_depends ELEMENTS blt::cuda IF AXOM_ENABLE_CUDA)
blt_list_append(TO my_component_test_depends ELEMENTS blt::hip IF AXOM_ENABLE_HIP)
Use the repository's existing local convention when modifying an existing CMakeLists.txt: some test directories use ENABLE_HIP for build-configuration workarounds such as axom_force_release_for_target(...), while dependency lists commonly use AXOM_ENABLE_HIP.
-DENABLE_TESTS=ON -DAXOM_ENABLE_TESTS=ONctestctest -R test_state_managersrc/cmake/AxomMacros.cmakesrc/axom/inlet/tests/CMakeLists.txtsrc/thirdparty/tests/CMakeLists.txt