co2*_*f2e 7 unit-testing rust rust-cargo
我在一个名为的软件包中有单元测试,school-info并且有一个名为的测试函数repeat_students_should_not_get_full_marks。
我可以通过运行模块中的所有测试cargo test --package school_info。
cargo test test-name将匹配并运行测试,其中包含test_name尽管没有帮助。
如何仅repeat_students_should_not_get_full_marks运行测试而不运行所有测试?我在文档中找不到执行此操作的命令。
使用cargo test test-name以test-name开头的过滤器测试。它可能可以运行多个测试。测试功能是否存在mod并不重要,它仍然能够执行多个测试。
您可以通过添加-- --exact为参数来避免这种情况 。
如果您的测试不在任何mod中,则可以像这样简单地执行:
cargo test test_fn_name -- --exact
Run Code Online (Sandbox Code Playgroud)
否则,您需要提供具有完整名称空间的测试:
cargo test test_mod_name::test_fn_name -- --exact
Run Code Online (Sandbox Code Playgroud)
对于您的情况,解决方案将是:
cargo test --package school_info repeat_students_should_not_get_full_marks -- --exact
Run Code Online (Sandbox Code Playgroud)