如何在 IntelliJ 中为所有 Rust/Cargo 测试设置 --nocapture 标志?

How to set the --nocapture flag for all Rust/Cargo tests in IntelliJ?

有没有办法让 IntelliJ's/CLion 的 Rust 插件使用 --nocapture 标志进行 Rust 测试?

我知道我可以为每个测试创建一个 "Run" 配置,但那是不可扩展的。

此外,IntelliJ 曾经打印 Cargo 命令,它是 运行 用于测试。现在输出 window 只显示 Testing started at 15:31 ...

您可以为所有配置自定义模板。请在 Run | Edit Configurations 选项卡上启用 Show stdout/stderr in tests (and disable tool window) 选项:screenshot

对于命令行用法添加一个别名:

.cargo/config:

[alias]
t = "test -- --nocapture"

运行 与:

$ cargo t

或保留颜色:

[alias]
t = "test -- --nocapture --color always"