You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过ctest强制运行已禁用的GTest测试用例?

强制运行GTest中DISABLED前缀的测试用例

我有一个基于CMake、CTest和GTest的C++项目。出于回归测试的需要,我使用GTest的命名技巧将某测试用例命名为DISABLED_test_name以禁用它,但希望能手动运行该测试。执行以下命令后:

$ ctest -R aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt --verbose
UpdateCTestConfiguration  from :/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Parse Config file:/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Parse Config file:/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Test project /scratch/bryanloz/aie_controller_hax/test/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 8
    Start 8: aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt
1/1 Test #8: aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt ...***Not Run (Disabled)   0.00 sec
No tests were found!!!

测试显示为未运行(已禁用),请问如何覆盖该行为,强制运行该测试?


解决方法

方法1:直接运行测试可执行文件

找到对应测试的可执行文件路径(通常在build目录下的测试子目录中),使用GTest专属参数强制运行禁用测试:

  • 运行目标测试(包含所有禁用的该测试用例):
    ./path/to/your/test_executable --gtest_also_run_disabled_tests --gtest_filter=aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt
    
  • 仅运行带DISABLED_前缀的目标测试:
    ./path/to/your/test_executable --gtest_filter=*DISABLED_aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt
    

方法2:通过CTest传递GTest参数

使用CTest的--test-arguments参数,将GTest的强制运行参数传递给测试可执行文件:

ctest -R aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt --verbose --test-arguments="--gtest_also_run_disabled_tests"

如果需要精准过滤特定禁用测试,可指定过滤规则:

ctest -R aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt --verbose --test-arguments="--gtest_filter=*DISABLED*"

内容的提问来源于stack exchange,提问作者CraigDavid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 10:25:35