【问题标题】:How to make cargo test show only the test which ran?如何使货物测试只显示运行的测试?
【发布时间】:2021-08-11 05:26:34
【问题描述】:

我运行 cargo test 并在实际测试文件之前和之后得到这个垃圾:

root@ub:~/backend/utils# cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.21s
     Running unittests (target/debug/deps/utils-d206bcff05f45684)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/helpers.rs (target/debug/deps/helpers-21ab86543f613060)

running 1 test
test tests::test_add ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests utils

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

看到那两个running 0 tests了吗?如何删除它们并仅显示运行的实际测试?

【问题讨论】:

    标签: rust


    【解决方案1】:

    这是一种减少额外输出量的方法:如果特定目标(库、二进制文件)没有任何测试,那么您可以通过 Cargo.toml 禁用其中正在运行的测试:

    [lib]
    test = false
    doctest = false
    
    [[bin]]
    name = "my-binary"
    test = false
    

    这将消除 cargo test 输出中的“运行 0 次测试”部分。

    当然,这会产生风险,您稍后会发现您编写了一个测试并且它没有运行,但是通过采用测试驱动的开发习惯来编写您知道会首先失败的测试,这可以得到帮助。

    【讨论】:

    • 我从事测试驱动开发。所以这对我有用,没有任何问题。谢谢
    猜你喜欢
    • 2020-06-08
    • 2021-04-30
    • 2018-07-12
    • 1970-01-01
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    相关资源
    最近更新 更多