On Mon, Aug 21, 2017 at 10:05:12PM +0200, 'Axel Wagner' via golang-nuts wrote:
> > Satisfying a standard interface like io.Reader or io.Writer correctly is > > not just a matter matching the function signatures, but rather adhering to > > behaviour that is documented in comments > > <https://golang.org/pkg/io/#Reader> > > > > Is there a standard way for me to specify an implementation of such an > > interface and run an existing suite of tests against it that verify the > > behaviour is indeed as expected? > > > > So, in other words, does something like testing.TestBehaviour( > > myReader,io.Reader) or testing.SatisfiesIoReader(myReader) exist? > > > > To clarify, I'm not asking how to write tests that verify the > > implementation of a standard interface. > > Rather, I want to know if there is a way I can reuse tests that already > > exist for an implementation that I wrote? > I think in general that will be very hard to do, generically. The reason > is, that the precise edge cases in which the behavior is critical depend so > much on your implementation. > > The best I can think of would be to write a wrapper which checks the > invariants given and run your implementation-specific testsuite using that. > Or to fuzz it. > > I'm aware that this doesn't answer your question (it's hard to prove a > negative and AFAIK the answer is "no"), but maybe it explains why the > problem is non-trivial. FTR, I would be interested in something like that > too. I'm afraid, there are no such test exposed to the general audience, but the standard package testing/iotest [1] might be of at least some help. 1. https://golang.org/pkg/testing/iotest/ -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.