

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345# Rust Testing67> This file extends [common/testing.md](../common/testing.md) with Rust-specific content.89## Test Framework1011- **`#[test]`** with `#[cfg(test)]` modules for unit tests12- **rstest** for parameterized tests and fixtures13- **proptest** for property-based testing14- **mockall** for trait-based mocking15- **`#[tokio::test]`** for async tests1617## Test Organization1819```text20my_crate/21├── src/22│ ├── lib.rs # Unit tests in #[cfg(test)] modules23│ ├── auth/24│ │ └── mod.rs # #[cfg(test)] mod tests { ... }25│ └── orders/26│ └── service.rs # #[cfg(test)] mod tests { ... }27├── tests/ # Integration tests (each file = separate binary)28│ ├── api_test.rs29│ ├── db_test.rs30│ └── common/ # Shared test utilities31│ └── mod.rs32└── benches/ # Criterion benchmarks33 └── benchmark.rs34```3536Unit tests go inside `#[cfg(test)]` modules in the same file. Integration tests go in `tests/`.3738## Unit Test Pattern3940```rust41#[cfg(test)]42mod tests {43 use super::*;4445 #[test]46 fn creates_user_with_valid_email() {47 let user = User::new("Alice", "alice@example.com").unwrap();48 assert_eq!(user.name, "Alice");49 }5051 #[test]52 fn rejects_invalid_email() {53 let result = User::new("Bob", "not-an-email");54 assert!(result.is_err());55 assert!(result.unwrap_err().to_string().contains("invalid email"));56 }57}58```5960## Parameterized Tests6162```rust63use rstest::rstest;6465#[rstest]66#[case("hello", 5)]67#[case("", 0)]68#[case("rust", 4)]69fn test_string_length(#[case] input: &str, #[case] expected: usize) {70 assert_eq!(input.len(), expected);71}72```7374## Async Tests7576```rust77#[tokio::test]78async fn fetches_data_successfully() {79 let client = TestClient::new().await;80 let result = client.get("/data").await;81 assert!(result.is_ok());82}83```8485## Mocking with mockall8687Define traits in production code; generate mocks in test modules:8889```rust90// Production trait — pub so integration tests can import it91pub trait UserRepository {92 fn find_by_id(&self, id: u64) -> Option<User>;93}9495#[cfg(test)]96mod tests {97 use super::*;98 use mockall::predicate::eq;99100 mockall::mock! {101 pub Repo {}102 impl UserRepository for Repo {103 fn find_by_id(&self, id: u64) -> Option<User>;104 }105 }106107 #[test]108 fn service_returns_user_when_found() {109 let mut mock = MockRepo::new();110 mock.expect_find_by_id()111 .with(eq(42))112 .times(1)113 .returning(|_| Some(User { id: 42, name: "Alice".into() }));114115 let service = UserService::new(Box::new(mock));116 let user = service.get_user(42).unwrap();117 assert_eq!(user.name, "Alice");118 }119}120```121122## Test Naming123124Use descriptive names that explain the scenario:125- `creates_user_with_valid_email()`126- `rejects_order_when_insufficient_stock()`127- `returns_none_when_not_found()`128129## Coverage130131- Target 80%+ line coverage132- Use **cargo-llvm-cov** for coverage reporting133- Focus on business logic — exclude generated code and FFI bindings134135```bash136cargo llvm-cov # Summary137cargo llvm-cov --html # HTML report138cargo llvm-cov --fail-under-lines 80 # Fail if below threshold139```140141## Testing Commands142143```bash144cargo test # Run all tests145cargo test -- --nocapture # Show println output146cargo test test_name # Run tests matching pattern147cargo test --lib # Unit tests only148cargo test --test api_test # Specific integration test (tests/api_test.rs)149cargo test --doc # Doc tests only150```151152## References153154See skill: `rust-testing` for comprehensive testing patterns including property-based testing, fixtures, and benchmarking with Criterion.155
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| ThanhTrunggDEV/DontBeLazy.cursor/rules/zh-agents.mdc · 6 | Cursor rules | no sections | 50/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/zh-patterns.mdc · 6 | Cursor rules | api | 30/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.agent/AGENTS.md · 6 | AGENTS.md | buildteststylearch+4 | 77/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/AGENTS.md · 6 | AGENTS.md | buildteststylearch+4 | 77/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-agents.mdc · 6 | Cursor rules | agent-behaviour | 50/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-code-review.mdc · 6 | Cursor rules | styletesting-strategygitsecurity+3 | 65/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-coding-style.mdc · 6 | Cursor rules | style | 54/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-development-workflow.mdc · 6 | Cursor rules | gitagent-behaviour | 39/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-git-workflow.mdc · 6 | Cursor rules | lint-formatgitagent-behaviour | 43/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-hooks.mdc · 6 | Cursor rules | styletypessecuritydo-not | 36/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-patterns.mdc · 6 | Cursor rules | lint-formatstyleapi | 52/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-performance.mdc · 6 | Cursor rules | buildperformance | 48/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-security.mdc · 6 | Cursor rules | security | 39/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-testing.mdc · 6 | Cursor rules | testtesting-strategyagent-behaviour | 34/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-coding-style.mdc · 6 | Cursor rules | lint-formatstyle | 52/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-hooks.mdc · 6 | Cursor rules | buildlint-formatdeployment | 60/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-patterns.mdc · 6 | Cursor rules | style | 54/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-security.mdc · 6 | Cursor rules | securityperformancedo-not | 73/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-testing.mdc · 6 | Cursor rules | testtesting-strategy | 55/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/csharp-coding-style.mdc · 6 | Cursor rules | lint-formatstyletypes | 66/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 46 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 14 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| bybren-llc/safe-agentic-workflow.cursor/rules/10-backend-python.mdc · 399 | Cursor rules | testlint-formatstylegit+4 | 97/100 | today |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/thanhtrunggdev-dontbelazy-cursor-rules-rust-testing)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.