Is it possible to use the cargo
command to run library tests (i.e.., cargo test --lib
) and documentation tests without running any integration tests (i.e., the tests in the crate's top-level tests
directory)? Bonus points are awarded for compiling the integration tests without running them.
Here's the bigger picture. My crate is a client library for a web service, and the HTTP server is not part of the crate. I've organized my crate into:
As such, it's sometimes unfeasible to have the HTTP server running on the machine building the crate—e.g., a Travis CI build agent. In these situations I would like to build all tests but exclude all integration tests from running because every integration test will fail.
The short answer is yes. For software to work properly, all units should integrate and perform as they're expected to. To ensure this is the case, you will need to perform integration tests.
Unit Testing is a kind of white box testing, whereas Integration Testing is a kind of black-box testing. For Unit Testing, accessibility of code is required, as it tests the written code, while for Integration Testing, access to code is not required, since it tests the interactions and interfaces between modules.
These differences may hamper module integration. In this case, integration tests work like a health check that identifies pain points to address. As for E2E testing, it is a testing type that automatically simulates user experience when working with the tool relying on the so-called user stories.
Now once you run npm run test , or jest , in the command line, it will create the test_book_database database, seed it with any migrations you had (to set up the schema and any necessary data), and you can access the database in each integration test.
Looking at cargo help test
(as you probably have):
cargo test --lib
cargo test --doc
tests/
without running them: cargo test --no-run --test NAME
, but you need to enumerate them yourself. Again it probably makes sense to add something to Cargo here.In the mean time, integration tests are really separate crates that use your library as a dependency. You could make them explicit with Cargo.toml
files and [dependencies] foo = {path = "…"}
so that cargo test
without arguments on your main crate doesn’t run them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With