day 43 @rust テスト2

・テスト用の関数
assert!(v);
assert_eq!(a,b);
assert_ne!(a, b);

アサーションメッセージのカスタム
assert!(v,
"custom sample{} {}"
true, 32);

・パニックが起こるかのテスト
should_panic属性を使う。
#[test]
#[should_panic]
fn sample() {}

・特定のパニックのみテストを通過するようにする。
#[should_panic(expected="panic")]

・Result型のテストをする。
戻り値をResult型にすればよい。
#[test]
fn test_func() -> Result<(), String> {
// some test.
}