{"id":26516416,"url":"https://github.com/corrode/write-yourself-some-tests","last_synced_at":"2026-03-12T09:26:23.773Z","repository":{"id":243730316,"uuid":"812663261","full_name":"corrode/write-yourself-some-tests","owner":"corrode","description":"Learn how to write effective and ergonomic tests in Rust","archived":false,"fork":false,"pushed_at":"2025-03-15T16:31:07.000Z","size":10357,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T17:27:29.738Z","etag":null,"topics":["rust","rustlang","testing","workshop","workshop-materials"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/corrode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-09T14:32:40.000Z","updated_at":"2025-03-15T16:36:43.000Z","dependencies_parsed_at":"2024-06-10T22:57:32.657Z","dependency_job_id":"09acbd4b-1c81-4157-8d81-cc60ba8c531a","html_url":"https://github.com/corrode/write-yourself-some-tests","commit_stats":null,"previous_names":["corrode/testing-workshop","corrode/write-yourself-some-tests"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrode%2Fwrite-yourself-some-tests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrode%2Fwrite-yourself-some-tests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrode%2Fwrite-yourself-some-tests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrode%2Fwrite-yourself-some-tests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/corrode","download_url":"https://codeload.github.com/corrode/write-yourself-some-tests/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244752349,"owners_count":20504256,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","rustlang","testing","workshop","workshop-materials"],"created_at":"2025-03-21T07:17:36.558Z","updated_at":"2026-03-12T09:26:18.732Z","avatar_url":"https://github.com/corrode.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Write Yourself Some Tests in Rust\n\n![Course Banner](/assets/banner.png)\n\nThis is a workshop about testing in Rust. It is intended for people who are already a bit familiar with Rust and want to learn more about testing in Rust.\n\n## Prerequisites\n\n- Basic knowledge of Rust.\n- A working Rust installation. (See https://rustup.rs/)\n- A working Rust IDE (e.g. Visual Studio Code with the Rust extension)\n  or an editor.\n\n## Slides\n\nOpen the [slides](/slides.pdf) to follow along with the workshop.\n\n## Exercises\n\nGo to the `src/exercises` module and follow the instructions there.\nYou can start with `basic.rs` and then move on to more advanced exercises.\n\n## Workshop Topics\n\nThis workshop is about testing in Rust. We will cover the following topics:\n\n- Writing unit tests in the same file as the code\n- Returning `Result` from tests\n- Keep tests close to the code\n- Writing integration tests\n- Integration tests vs functional tests\n- Doctests\n- Test doubles\n  - Mocks\n  - Traits\n- Tips and tricks\n  - You can return `Result` from tests\n  - `#[ignore]` attribute\n  - Testing panics `#[should_panic]`\n  - `#[cfg(test)]` for convenience methods\n- Test isolation\n  - Isolating the filesystem: `tempdir`\n  - Isolating the network: HTTP mocking\n  - Isolating external dependencies: `mockall`\n- Speeding up tests\n  - Unit tests over integration tests\n  - Faster integration tests: use a single compilation unit\n  - cargo test runs tests in parallel\n  - cargo nextest\n  - sequential tests with `--test-threads=1` or \n    https://crates.io/crates/serial_test\n- Exploratory testing\n  - Property-based testing\n  - Mutation testing\n- Benchmark tests\n- Structuring code for better testing\n  Onion Architecture / Hexagonal Architecture\n- Test coverage: `cargo tarpaulin --out Html`\n\n## Running the tests\n\nIf you want to run unit tests only, you can use the `--lib` flag:\n\n```sh\ncargo test --lib\n```\n\nTo run only the integration tests, you can use the `--test` flag:\n\n```sh\ncargo test --test '*'\n```\n\nTo run a specific test, you can use the `--test` flag with the test name:\n\n```sh\ncargo test --test fibonacci_is_prime\n```\n\n## Notable Frameworks and Libraries\n\n### Test Runners\n\n- [cargo-nextest](https://nexte.st/): A faster test runner for Rust.\n\n### Parameterized Testing\n\n- [rstest](https://github.com/la10736/rstest): Write parameterized tests in Rust.\n- [test-case](https://github.com/frondeus/test-case): Another parameterized testing library.\n\n### Property-Based Testing\n\n- [quickcheck](https://github.com/BurntSushi/quickcheck): Automated property-based testing with shrinking support.\n- [proptest](https://github.com/proptest-rs/proptest): Another property-based testing library.\n\n### Permutation Testing\n\n- [loom](https://crates.io/crates/loom): a testing tool for concurrent code, which runs a test many times, permuting the possible concurrent executions.\n\n### Mocking and Test Doubles\n\n- [mockall](https://github.com/asomers/mockall): Trait-based mocking library.\n- [mockito](https://github.com/lipanski/mockito): HTTP mocking library.\n- [httpmock](https://github.com/alexliesenfeld/httpmock): Another HTTP mocking library.\n\n### Testing Command Line Applications\n\n- [assert_cmd](https://github.com/assert-rs/assert_cmd): Test command line applications.\n\n### Filesystem and Network Isolation\n\n- [tempfile](https://github.com/Stebalien/tempfile): Create temporary files and directories.\n\n### Testing Snapshots\n\n- [insta](https://github.com/mitsuhiko/insta?tab=readme-ov-file): Snapshot testing library.\n\n### Faking Data\n\n- [fakeit](https://crates.io/crates/fakeit): Fake data generator library with 130+ functions.\n\n### Test Context Management\n\n- [test-context](https://crates.io/crates/test-context): A library for writing tests with setup and teardown functions.\n\n### Embedded Testing\n\n- [embedded-test](https://github.com/probe-rs/embedded-test): A test harness and runner for embedded devices \n\n### Little Helpers\n\n- [pretty_assertions](https://github.com/rust-pretty-assertions/rust-pretty-assertions): Alternative to `assert_eq!` with better diffing and color support.\n- [assertor](https://github.com/google/assertor): Fluent assertion library for Rust with readable messages.\n\n### Test Coverage\n\n```\ncargo +stable install cargo-llvm-cov --locked\ncargo llvm-cov test --open\n```\n\n### Procedural Macro Testing\n\n- [trybuild](https://crates.io/crates/trybuild): Testing procedural macros.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorrode%2Fwrite-yourself-some-tests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorrode%2Fwrite-yourself-some-tests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorrode%2Fwrite-yourself-some-tests/lists"}