Integration tests
While unit tests can test the private interface of your crate and individual modules, integration tests are kind of like black box tests that aim to test the end-to-end use of the public interface of your crate from a consumer's perspective. In terms of writing code, there is not a lot of difference between writing integration tests and unit tests. The only difference lies in the directory structure and that the items need to be made public, which is already exposed by the developer as per the design of the crate.
First integration test
As we stated previously, Rust expects all integration tests to live in the tests/
directory. Files within the tests/
directory are compiled as if they are separate binary crates while using our library under test. For the following example, we'll create a new crate by running cargo new integration_test --lib
, with the same function, sum
,as in the previous unit test, but now we have added a tests/
directory, which has an integration test...