Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run library tests and doc tests but not integration tests

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:

  1. Library tests, which do not depend on the HTTP server,
  2. Documentation tests, which do not depend on the HTTP server, and
  3. Integration tests, which require the HTTP server to be running on the localhost.

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.

like image 959
Craig M. Brandenburg Avatar asked Jan 14 '16 15:01

Craig M. Brandenburg


People also ask

Do you need integration tests?

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.

What's the difference between unit test and integration test?

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.

What is the difference between integration testing and end to end testing?

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.

Can jest be used for integration testing?

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.


1 Answers

Looking at cargo help test (as you probably have):

  • Running only tests in the library: cargo test --lib
  • Running only doc-tests: cargo test --doc
  • Building tests in 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.

like image 55
Simon Sapin Avatar answered Oct 22 '22 12:10

Simon Sapin