How to define test-only dependencies?

Yes. Use dev-dependencies. From the Cargo docs:

You can add a [dev-dependencies] section to your Cargo.toml whose format is equivalent to [dependencies]:

[dev-dependencies]
tempdir = "0.3"

Dev-dependencies are not used when compiling a package for building, but are used for compiling tests, examples, and benchmarks.

When possible, you should also use Cargo's resolver version 2 to better handle complicated dev-dependency cases.