Instead of making multiple small assertions that check individual fields or conditions, write single comprehensive assertions that verify the complete expected state. This approach makes tests more maintainable, provides better documentation of expected behavior, and makes test failures more informative.
Instead of making multiple small assertions that check individual fields or conditions, write single comprehensive assertions that verify the complete expected state. This approach makes tests more maintainable, provides better documentation of expected behavior, and makes test failures more informative.
Example - Instead of:
assert_eq!(tools[0]["type"], "function");
assert_eq!(tools[0]["name"], "shell");
assert!(tools.iter().any(|t| t.get("name") == Some(&name.clone().into())));
Prefer:
assert_eq!(tools, vec![
json!({
"type": "function",
"name": "shell"
}),
json!({
"type": "function",
"name": name
})
]);
This practice:
When dealing with complex objects that don’t implement PartialEq, consider implementing it to enable comprehensive assertions rather than checking fields individually.
Enter the URL of a public GitHub repository