Hello, I have more then one question, so I’ve decided to start discussion here:
I’ve pushed my project to github (yeap, it’s url shortener one more time) -> https://github.com/raventid/coursera_learning/tree/master/url_shortener
to make a few references here.
I followed a pretty straightforward approach, in my opinion, and organized my project like this:
I’ve created file
tests.rs to put my integration tests there and file
main.rs to put my code in it. And successfully runned tests with
cargo test. BTW rocket app started successfully too and I was pretty happy.
Then I’ve decided to create folder storage for storage adapters, like redis or other stuff, and write unit tests for them right in the according files.
I’ve tried to run my storage units with
cargo test storage (and a few more times
storage/please) and failed.
Then I’ve tried to move my
tests/integration_tests.rs. And they stopped to work) I found a note that my integration tests in separate folder are external crates, but I was not able to use
extern crate url_shortener here(is it right?). -> https://github.com/raventid/coursera_learning/blob/master/url_shortener/tests/integration_test.rs#L1
I’ve been looking at diesel-rs and servo projects and a few more to see how other people organize their projects. As I understand right now I should organize each folder
as a separate package (I’m not sure about “package” term, but I mean “package” word from Cargo.toml). To me it looks weird and feels like puting Gemfile in each folder
Latter, I found crossbeam project, they have unit tests in separate files and only root Cargo.toml for project. So I’m confused, how they run this tests?
So my questions are:
- Should I create
Cargo.tomlfile for each subfolder of my project and run specs inside of this subfolder, is it default project structure?
- How to run unit tests for specific file in specific folder, i.e.
cargo run /lib/users/credit_cards.rs? I imagine this like wrapping particular file with a
mainfunction and running tests against that.
- Should I do something with my
extern crate url_shortenerin my integration tests, when I put them in separate tests folder?
And I’m not yet confident about my understanding what
crate is and how to deal with Rust modularity, so perhaps I googled my problems the wrong way