A testing library focused on turning failure into success, actually
.
- Builder interface to make test code obvious
- Consistent method name to reduce things you have to remember
- Specific fail report to save your time
- There are helpers to see details of a failure
package main
import (
"testing"
a "github.com/bayashi/actually"
pb "github.com/bayashi/actually/testpb"
)
func TestObject(t *testing.T) {
love, err := getLove()
a.Got(err).NoError(t)
a.Got(love).True(t)
}
func getLove() (bool, error) {
return true, nil
}
func TestObjects(t *testing.T) {
x := map[string]int{
"foo": 123,
}
y := map[string]int{
"foo": 123,
}
// `Same` method verifies that two objects are same in value and type.
// Function type value is not acceptable. And not verify pointer address.
// It will be fail, int(1) and uint(1), because of type.
a.Got(x).Expect(y).Same(t)
// Cmp method gets the differences between two objects by go-cmp.Diff.
a.Got(x).Expect(y).Cmp(t)
}
func TestProtoMessages(t *testing.T) {
x := &pb.Foo{Id: 123}
y := &pb.Foo{Id: 123}
// CmpProto method gets the differences between two Protobuf messages
// by go-cmp.Diff with protocmp.Transform option.
a.Got(x).Expect(y).CmpProto(t)
a.Got(x).Expect(y).SamePointer(t) // This test will be failed
}
- True, False, Nil, NotNil, NoError
- Same, SamePointer, SameType, SameConvertibleNumber
- NotSame, NotSamePointer, NotSameType, NotSameConvertibleNumber
- Cmp, CmpProto, CmpAllowUnexported, CmpIgnoreUnexported, (CmpOpt)
- Panic, NoPanic, PanicMessage
- Match, NotMatch
- Len
Here is a Wiki of full API documentation.
actually
will help you with evident fail report:
package foo
import (
"testing"
a "github.com/bayashi/actually"
)
func Test(t *testing.T) {
x := "foo\nbar\nbaz"
y := "foo\nbar\nbug"
a.Got(x).Expect(y).Same(t)
}
Above code will put fail report like below:
=== RUN Test
foo_test.go:10:
Test name: Test
Trace: /path/to/foo_test.go:10
Fail reason: Not same value
Type: Expect:string, Got:string
Expected: "foo\nbar\nbug"
Actually got: "foo\nbar\nbaz"
Diff details: --- Expected
+++ Actually got
@@ -2,2 +2,2 @@
bar
-bug
+baz
--- FAIL: Test (0.00s)
There are some helpful methods.
actually
has the Debug("label", any_variable)
method to show additional data only in fail report.
Like below, src
variable will be dumped nicely only on fail.
res := someFunc(src)
actually.Got(res).Debug("src", src).True(t)
go get github.com/bayashi/actually
MIT License
Dai Okabayashi: https://github.com/bayashi
Inspired by: