Write comprehensive tests that cover all relevant cases and variations while maintaining proper organization and structure. Key practices: 1. Place tests in appropriate locations (e.g., core tests in `library/coretests`)
Write comprehensive tests that cover all relevant cases and variations while maintaining proper organization and structure. Key practices:
library/coretests
)Example:
// In library/coretests/your_module.rs
#[test]
fn test_feature_behavior() {
// Test primary functionality
let result = do_something();
assert_eq!(result.primary(), expected);
// Test analogous case
let alt_result = do_something_similar();
assert_eq!(alt_result.similar(), expected);
// Test backwards compatibility
assert_eq!(result.legacy_method(), old_expected);
assert_eq!(result.new_method(), new_expected);
}
// Separate file for failure cases
// In tests/ui/your_module_failures.rs
//@ build-fail
//@ ignore-pass
fn test_invalid_case() {
// Test expected failure
let result = invalid_operation();
//~^ ERROR expected error message
}
Enter the URL of a public GitHub repository