Integration tests extern crate: can't find crate error

I have a few files in the src folder which I use in main.rs like so:

   mod client;
   mod node;
   use client::client_add;
   use node::node_add;

and between the files themselves like so:

use crate::client::client_add;

Cargo builds and runs as it's supposed to.

However, if I try to import one of the files in the tests/integration_tests.rs like so:

extern crate node;

, I'm getting the can't find crate error. There is not much more information on integration tests in the Rust book.

What am I missing?

Here's a link to the project to make the structure clear:
test project

test-mod is the crate, in a library you would export the modules like pub mod node;. What you have is instead is just a executable.

Have a read through this, it complements other books.
https://rust-lang-nursery.github.io/cli-wg/tutorial/testing.html

Thanks for the link to the book, it's very informative. I suppose there is nothing like testing binary crates in external tests. It's either a lib, or no integration tests. Unless we use std::process::Command;. Thank you for the reply.

Thank you for confirming this explicitly, I searched the half web through to find out how to do integration test on binaries. It's a bit sad that it is just not possible.

Sure, you can do integration tests on binaries, cargo is I believe a good example of an executable that uses a lot of integration testing. Another example is rq. You just have to write tests that call your executable.

If you want to test the functions used in your executable with an "integration test", another approach is to make your crate provide both a library and an executable.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.