mcpField
R
rust-tests-guidelines

rust-tests-guidelines

github.com/redisearchTesting & quality6.2k71 installsUpdated today
Repository

About rust-tests-guidelines

rust-tests-guidelines is a set of guidelines for writing tests for Rust code. It is intended for developers who need conventions for test design, organization, and handling C symbols.

Key features

  1. 01Prefer testing through public APIs
  2. 02Use insta for hard-to-compare output
  3. 03Apply proptest to suitable invariants
  4. 04Organize integration tests by crate
  5. 05Co-locate tests that need private APIs
  6. 06Document extern C test requirements

Use cases

  1. 01Plan tests for a new Rust component
  2. 02Choose between public and private API tests
  3. 03Structure a crate's integration tests
  4. 04Test unpredictable output or key invariants

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/redisearch/redisearch --skill rust-tests-guidelines

After installing, type/rust-tests-guidelinesin Claude Code to confirm it loaded.

Details

From the project README

Guidelines for Writing Rust Tests

Guidelines for writing new tests for Rust code.

Guidelines

  1. Test against the public API of the code under test.
  2. Test private APIs if and only if the private component is highly complex and difficult to test through the public API.
  3. Use insta whenever you are testing output that is difficult to predict or compare.
  4. Where appropriate, use proptest to add property-based tests for key invariants.
  5. Testing code should be written with the same care reserved to production code. Avoid unnecessary duplication, introduce helpers to reduce boilerplate and ensure readability. The intent of a test should be obvious or, if not possible, clearly documented.
  6. Do not reference exact line numbers in comments, as they may change over time.

Code organization

  1. Put tests under the tests directory of the relevant crate if they don't rely on private APIs.
  2. The tests directory should be organized as a crate, with a main.rs file and all tests in modules. Refer to the trie_rs/tests directory as an example.
  3. If the test must rely on private APIs, co-locate them with the code they test, using a #[cfg(test)] module.

Dealing with extern C symbols

Check out CONTRIBUTING.md for instructions on how to deal with undefined C symbols in Rust tests.

Comments

Markdown supported