rust-testing-strategy

Guides writing Rust unit, integration, and snapshot tests with cargo-nextest and insta.

1.6k|122|Updated Jul 15, 2019
One-click install
npx skills add https://github.com/hashintel/hash --skill rust-testing-strategy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-testing-strategy
Source: https://github.com/hashintel/hash/tree/main/.agents/skills/rust-testing-strategy
Command: npx skills add https://github.com/hashintel/hash --skill rust-testing-strategy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust developers often write inconsistent tests with unclear assertions, poor organization, and missing edge-case coverage. This Skill standardizes how Rust tests are written, structured, and executed across the HASH monorepo.

Core Features & Use Cases

  • Test Execution Standards: Defines when to use cargo-nextest for unit and integration tests versus the default runner for documentation tests, plus clippy and cargo doc verification commands.
  • Assertion Conventions: Enforces descriptive "should..." assertion messages, preferring expect() over unwrap() and assert_eq! with custom messages.
  • Test Organization & Design: Covers Arrange-Act-Assert structure, module grouping, naming rules (no test_ prefixes), parameterized tests, and edge-case coverage.
  • Use Case: When adding a new Rust function with error paths, use this Skill to generate tests covering happy paths, each error variant, and boundary conditions with properly formatted assertion messages.

Quick Start

Write Rust tests for my new parser function following the HASH testing strategy, covering error cases and using proper assertion messages.

Frequently Asked Questions about rust-testing-strategy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run Rust tests with cargo-nextest?

Use cargo-nextest to run unit and integration tests in the workspace, while documentation tests still require the default cargo test runner. For full verification, also run clippy with --all-features --all-targets --workspace --no-deps.

What assertion style should Rust tests use?

All assertion messages, including expect(), unwrap(), and assert*() calls, should follow the "should..." format, such as value.expect("should contain a valid configuration"). Prefer expect() or expect_err() with clear messages over unwrap(), and use assert_eq! with custom messages.

How should I name and organize Rust test functions?

Do not prefix test function names with test_, and group related tests into modules with descriptive names explaining the scenario and expected outcome. Use helper functions to reduce duplication and consider parameterized tests for similar inputs.

Should I use insta for snapshot testing in Rust?

Yes, insta is the designated tool for snapshot testing in this strategy, alongside similar_asserts for diff-friendly comparisons. It fits scenarios where output is large or structured and manual assertions would be brittle.

How do I build JSON test data in Rust tests?

Use the json! macro from serde_json instead of constructing JSON as raw strings. This avoids escaping errors, keeps test data readable, and produces proper serde_json::Value objects for assertions.