This package shows how you can extend the functionality of be without modifying the original package.
| Decorator | Effect |
|---|---|
tb.Diff |
Pretty-prints differences with cmp.Diff |
tb.JSON |
Shows values as JSON |
tb.Require |
Turns Error into Fatal (stop test on failure) |
All decorators work by wrapping testing.TB, so original be stays untouched.
go get github.com/yourusername/be-tb@latestbe.Equal(tb.Diff(t), got, want)Output:
diff (-want +got):
model.Subscription{
UserID: uuid.UUID{
- 0x2b,
+ 0x3b,
},
- EndDate: model.MonthYear{Time: s"2025-12-01 00:00:00 +0000 UTC"},
+ EndDate: model.MonthYear{Time: s"2025-11-01 00:00:00 +0000 UTC"},
}
NOTE: tb.Diff works only with a single want and requires matching types. Falls back to standard formatting otherwise.
be.Equal(tb.JSON(t), got, want)Output:
>>>>>>> got
{
"user_id": "60601fee-3bf1-4721-ae6f-7636e79a0cba",
"end_date": "11-2025"
}
=======
{
"user_id": "60601fee-2bf1-4721-ae6f-7636e79a0cba",
"end_date": "12-2025"
}
<<<<<<< want
be.True(tb.Require(t), condition)
be.Equal(tb.Require(t), got, want)ATTENTION: The entrance to the rabbit hole :)
be.True(tb.Require(tb.Diff(t)), condition)See example_test.go and example_test.out for a complete example.