Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 1.11 KB

File metadata and controls

64 lines (46 loc) · 1.11 KB

Quick Reference

Quick reference guide for common testing patterns.

Test Naming

it_should_{expected_behavior}_when_{condition}
it_should_{expected_behavior}_given_{state}

AAA Pattern

// Arrange: Set up test data
let data = setup();

// Act: Execute the behavior
let result = perform_action(data);

// Assert: Verify the outcome
assert_eq!(result, expected);

Parameterized Tests

use rstest::rstest;

#[rstest]
#[case(input1, expected1)]
#[case(input2, expected2)]
fn it_should_handle_various_inputs(#[case] input: Type, #[case] expected: Type) {
    // Test logic
}

Using MockClock

let clock = Arc::new(MockClock::new(fixed_time));
let component = Component::new(clock);

Using TempDir

let temp_dir = TempDir::new().unwrap();
let path = temp_dir.path();
// TempDir automatically cleans up when dropped

Test Builders

let (command, _temp_dir) = CommandTestBuilder::new().build();

Silent Test Output

let context = TestContext::new(); // Uses silent verbosity by default
let output = TestUserOutput::wrapped_silent();