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

为何cargo nextest识别到测试用例却未运行部分用例?

关于cargo nextest测试未全部运行的异常问题

初始测试现象

运行自研测试用例时,得到如下测试摘要:

Summary [   0.598s] 26/28 tests run: 24 passed, 2 failed, 0 skipped

为了得到“整数”的运行测试数,注释掉部分测试后,报告变为:

Summary [   0.588s] 27 tests run: 26 passed, 1 failed, 0 skipped

随后向mod tests中添加如下测试:

#[test]
fn do_test() -> Result<()> {
    assert!(false);
    Ok(())
}

此时得到的报告为:

Summary [   0.607s] 26/28 tests run: 24 passed, 2 failed, 0 skipped

“2个失败”符合预期,但通过的测试数意外减少了2个。

问题澄清(根据评论更新)

实际上26/28 tests表示总共有28个测试,但仅运行了26个,因此核心问题变为:为何这2个测试未被运行?

测试中使用了mockall crate,包括#[double]指令。

更多测试细节

某次运行显示启动时将运行29个测试,但最终摘要显示4个测试未运行:

(doc_indexer) D:\...\populate_index_module>cargo nextest run -v
   Compiling populate_index_module v0.1.0 (D:\...\populate_index_module)
    Finished test [unoptimized + debuginfo] target(s) in 4.33s
    Starting 29 tests across 4 binaries
        PASS [   0.031s] populate_index_module auxiliaries::tests::working_up_from_app_execution_cwd_finds_doc_indexer_project_root_dir
        PASS [   0.025s] populate_index_module handling_framework::tests::unreadable_zip_complaint_causes_continue_not_error_propagation::case_1
        ...
        PASS [   0.088s] populate_index_module::test_1 ldocs_contain_more_than_one_para
        FAIL [   0.232s] populate_index_module text_document::tests::deliberately_failing_test

测试运行报告末尾:

PASS [   0.557s] populate_index_module::test_1 all_text_in_files_is_correctly_caught::case_2
------------
     Summary [   0.599s] 25/29 tests run: 22 passed, 3 failed, 0 skipped
        FAIL [   0.232s] populate_index_module text_document::tests::deliberately_failing_test
        FAIL [   0.266s] populate_index_module::test_1 framework_init_populates_the_index_by_submitting_bulk_inserts
        FAIL [   0.208s] populate_index_module::test_1 test_thing
error: test run failed

注:上述启动列表仅展示17个结果,总测试数更多是因为使用了rstest crate进行测试参数化。

异常运行现象

cargo nextest提供了多个选项(可执行cargo nextest run --help查看),尝试使用--run-ignored all选项后,结果极不稳定:有时运行全部29个测试,有时是26/29,有时23/29,有时27/29。这些未运行的测试并非手动标记为跳过,完全是由nextest自行决定不运行。

请求解释这一现象,并告知nextest文档中相关说明的位置。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 05:23:15