[英]Pointers on how to to get a test jar to run a separate war for testing (perhaps with cargo?)
[英]How to configure cargo test with custom arguments in VSCode
我有一些创建/读取/写入/删除文件的测试,并且我总是在每个测试中使用相同的文件名,因此我需要按顺序运行它们以避免同时对同一文件进行操作。 在命令行中我可以这样做
cargo test -- --test-threads=1
但是在 VSCode 运行/调试菜单中,它似乎不起作用。 我将自动生成的配置与 Rust Analyzer 一起使用,以及这些额外的参数用于顺序运行。
这是我的launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'my-project'",
"cargo": {
"args": [
"build",
"--bin=my-project",
"--package=my-project"
],
"filter": {
"name": "my-project",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'my-project'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin my-project",
"--package my-project",
"--", // here I've added the arguments
"--test-threads=1", // here I've added the arguments
],
"filter": {
"name": "my-project",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
这是我在运行第二个命令(调用cargo test
的命令)时得到的输出:
Running `cargo test --no-run --bin my-project --package my-project --message-format=json -- --test-threads=1`...
error: Found argument '--bin my-project' which wasn't expected, or isn't valid in this context
Did you mean '--bin'?
If you tried to supply `--bin my-project` as a value rather than a flag, use `-- --bin my-project`
USAGE:
cargo.exe test --no-run --bin [<NAME>]
For more information try --help
VSCode 使用两步流程:
cargo test --no-run
来编译测试可执行文件和 您应该将--test-threads=1
放在最后一个args
数组中:
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'my-project'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=my-project",
"--package=my-project",
],
"filter": {
"name": "my-project",
"kind": "bin"
}
},
"args": [ "--test-threads=1" ],
"cwd": "${workspaceFolder}"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.