Enhancing testing

Testing in Go can be very verbose, on account of having to check, and trigger the appropriate log and failure functions. A quick look at some tests in Dgraph at present, there’s some redundant testing calls, like t.Error and then t.Fail. Further, when there are failures, the testing package doesn’t actually provide location where failure occurred.

I’ve been using https://github.com/stretchr/testify for testing. It still uses the Go Test conventions, and the testing package can still be used and is appropriate in some circumstances. However it splits the Fail/FailNow ideas into assert/require, provides location details on all failures, and gives pretty printing of reasons for failure at a higher level than the testing package by default. Here’s an example of its use: https://github.com/anacrolix/missinggo/blob/master/hostmaybeport_test.go. You can well imagine to do this using pure standard library would be several times longer, and probably contain many formatting mistakes that wouldn’t be apparent unless errors actually occured.

I’ve found the package to be stable, lightweight, and straightforward to use. There’s no need to retrofit it to any existing tests.


Sure, sounds like a good idea. Maybe do a big sweep across the code base and enable testify library across it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.