Additional test input files


Where am I supposed to put additional test input files in the Cargo directory input files, and how should I access them from my test cases? The files are small binary files, but I don’t want to base64-encode them and put them directly into the test sources.

Reading Test dependency binary no longer found under unqualified name, I don’t want to put together a quick hack which works today, but can break any time.


You can use env!("CARGO_MANIFEST_DIR") to get path to the crate directory. You need to add relative path to your input file manually.

There doesn’t seem to be any convention for exact location of these files. I would just create a separate directory for them at the crate root.


The most dependable way is to use include_bytes! or include! to pull them into your test binary at compile time, since the path locations you provide are always relative to the directory containing the Rust code you’re editing. Example: