liveBook · Manning

Ignore annotation

As explained in Rust Servers, Services, and Apps

The Rust ignore annotation marks a test so that the test executor skips it during ordinary test-suite execution.

The #[ignore] annotation marks an individual test for exclusion from ordinary cargo test execution. Use it when a test changes persistent database state and repeated runs could fail, such as inserting a duplicate primary key. section 5.4 section 6.2.2

Ignoring a database-mutating test

Place #[ignore] immediately above the asynchronous test attribute: #[ignore] #[actix_rt::test] async fn post_course_success() { // inserts a course into the database } Running cargo test --bin iter4 then reports post_course_success as ignored while executing the other tests. The ignored test can remain available for deliberate execution when its database side effects are acceptable. section 5.4 section 6.2.2

Apply the annotation when:

  • A test inserts a fixed record and a later run could violate a database uniqueness constraint. section 5.4
  • A sanity-check suite should exercise retrieval and failure cases without creating new records every time. section 6.2.2
  • You want the test implementation preserved while excluding it from the default suite result. section 5.4
#[ignore]
    #[actix_rt::test]
    async fn post_course_success() {
    }

Inspect the minimal attribute placement used to exclude post_course_success from ordinary asynchronous test execution. section 5.4

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains attribute placement, database-side-effect rationale, and ignored-test output, but stops short of advanced test filtering.
Examples
Uses post_course_success, duplicate course_id insertion, and a three-test report containing two passed and one ignored test.
What it assumes
Assumes familiarity with Rust test functions, asynchronous test attributes, Cargo commands, and database-backed API tests.
What you can do after
Operate Cargo test runs that preserve side-effecting tests without executing them in routine sanity checks.
How it connects
Connects Rust attributes with Cargo test, asynchronous tests, and database-backed API testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.