A testing library focused on turning failure into success, actually.
- It is clear what is being tested by the builder interface
- Consistent method names to reduce things you have to memorize
- Explicit test failure results help you save time
- There are helper methods 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
- FailNow: Halt the test case immediately when the test fails
- Diff: Get diff of 2 objects on anywhere
- Dump: Get dumped string of objects on anywhere
- Debug: Show debug info only on failure
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:13: Test Fail reason: Not same value Expected: "foo\nbar\nbug" Actually got: "foo\nbar\nbaz" Diff details: --- Expected +++ Actually got @@ -2,2 +2,2 @@ bar -bug +baz Trace: /path/to/foo/foo_test.go:13 --- FAIL: Test (0.00s) If you set true value (i.e. "1", "true" or "TRUE" etc) into ENV:ACTUALLY_TRACE_SOURCE on running a test, then you can see a piece of source code for each stack trace in fail report.
=== RUN Test foo_test.go:13: Test Fail reason: Not same value Expected: "foo\nbar\nbug" Actually got: "foo\nbar\nbaz" Diff details: --- Expected +++ Actually got @@ -2,2 +2,2 @@ bar -bug +baz Trace: /path/to/foo/foo_test.go:13 10 x := "foo\nbar\nbaz" 11 y := "foo\nbar\nbug" 12 13> a.Got(x).Expect(y).Same(t) 14 } --- FAIL: Test (0.00s) go get github.com/bayashi/actually MIT License
Dai Okabayashi: https://github.com/bayashi
Inspired by: