rust 按名称对“货物测试”中的测试进行排序

gfttwv5a  于 2023-01-05  发布在  其他
关注(0)|答案(1)|浏览(144)

我正在用cargo test运行一些测试,我希望这些测试按字母顺序排序。如果我运行cargo run,我会得到如下结果:

test node::tests::start_node::get_value_start ... ok
test node::tests::start_node::get_value ... ok
test node::tests::start_node::set_value ... ok
test node::tests::main_node::test_new ... ok
test main_tests::run_checks ... ok
test node::tests::start_node::test_new ... ok
test sigmoid::tests::sig_deriv_f32 ... ok
test sigmoid::tests::sig_deriv_inf::test_f32 ... ok
test sigmoid::tests::sig_deriv_inf::test_f64 ... ok
test training_data::tests::iter_chunks ... ok
test training_data::tests::get_chunks ... ok
test sigmoid::tests::sig_inf::test_f64 ... ok
test sigmoid::tests::sig_f32 ... ok
test sigmoid::tests::sig_inf::test_f32 ... ok
test sigmoid::tests::sig_deriv_f64 ... ok
test sigmoid::tests::sig_f64 ... ok

并且每次以不同的、看似随机的顺序输出测试。
是否有一种方法可以输出测试,使它们按字母顺序排序,类似于:

test main_tests::run_checks ... ok
test node::tests::main_node::test_new ... ok
test node::tests::start_node::get_value_start ... ok
test node::tests::start_node::get_value ... ok
test node::tests::start_node::set_value ... ok
test node::tests::start_node::test_new ... ok
test sigmoid::tests::sig_deriv_f32 ... ok
test sigmoid::tests::sig_deriv_f64 ... ok
test sigmoid::tests::sig_deriv_inf::test_f32 ... ok
test sigmoid::tests::sig_deriv_inf::test_f64 ... ok
test sigmoid::tests::sig_f32 ... ok
test sigmoid::tests::sig_f64 ... ok
test sigmoid::tests::sig_inf::test_f32 ... ok
test sigmoid::tests::sig_inf::test_f64 ... ok
test training_data::tests::iter_chunks ... ok
test training_data::tests::get_chunks ... ok
juzqafwq

juzqafwq1#

默认情况下,它们已经按字母顺序运行,问题是它们也是并行运行的,并且会尽快输出结果以保存时间。如果您希望输出按排序顺序排列,则必须通过将测试框架限制为一个线程来连续运行测试:

cargo test -- --test-threads=1

请注意,这很可能会增加测试所需的时间。

相关问题