Hi HN, I'd like to show you Testy [0], a small testing library for golang that I've just released today.
Golang is interesting because it has an extremely powerful builtin testing framework, `testing`, that supports both soft and hard checks/assertions. Soft checks mark the test as failed but allow it to continue running. Hard checks mark the test as failed and immediately cause it to end, like asserts traditionally do in most languages.
There are a few established testing libraries (testify [1], gotest.tools [2], and is [3]) that take advantage of this in various ways, but they each have drawbacks.
- testify supports both hard and soft style checks. They call the soft checks "asserts", and the hard checks "requires", to the confusion of all. Their API has a massive surface area, which is confusing for developers trying to write tests. It uses `reflect.DeepEquals` for deep equality, which is painful for common operations like comparing `time.Time` structs. And their API isn't typesafe, so refactoring existing tests is a pain.
- gotest.tools has a smaller API surface area, and does some cool tricks with AST parsing in order to show meaningful failure messages. It uses `go-cmp` for deep equality, which is the right choice. But the API is confusing, the not typesafe, and it doesn't have soft style checks for everything.
- is has a too-small API surface area, to the point that it's missing NotEquals checks. It is also built around `reflect.DeepEquals`, and is not typesafe.
Testy, my new library, addresses all of these issues. It's typesafe, using generics. It uses `go-cmp` for deep equality testing. It has soft checks and hard asserts. It has a small, but sufficient, API surface area that makes it easy to learn and use. And it comes with structural helpers for giving your tests clearer meaning and failure output, making your tests more useful.
Give it a shot and let me know what you think! My one big question is whether or not to expand the surface area of the API and add more helpers, for things like comparing lengths, checking whether or not an object is in a slice or map, etc. Comments and feedback appreciated greatly!
[0] https://github.com/peterldowns/testy
[1] https://github.com/stretchr/testify
[2] https://github.com/gotestyourself/gotest.tools
[3] https://github.com/matryer/is