stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.5k stars 1.6k forks source link

Feature: Support hamcrest style matchers #729

Open scr-oath opened 5 years ago

scr-oath commented 5 years ago

By adding one more assertion function "That", which took t, an object, and a Matcher, you could support hamcrest-style matching and extension of the assertions without need for PRs in this repo.

"hamcrest-style" would translate to something like the following in go:

assert.That(t, 123, is.GreaterThanInt(99))

You could make Matcher the same way as the hamcrest java matcher, or fit it to be more go-like, but the gist is the same, that hamcrest style can provide readable test-DSL, descriptive error messages, and customer-extensibility of new assertions.

/cc @davedevelopment

scr-oath commented 5 years ago

http://hamcrest.org/JavaHamcrest/tutorial

stefano-bossi commented 3 years ago

this would be a fantastic improvement, it would stop the increase of assert* methods