> It seems the enthusiasm for this kind of testing is less than
> overwhelming, so let me share my experience.
There's a strong preference for a minimalist design on testing, and to
be honest testing panics has been a bit rare in the standard library,
so that's why you're not getting much excitement.
That said, I do want to integrate something like this in gocheck:
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/blog
http://niemeyer.net/twitter
No, that's only true for some functions. The standard library does
have functions that panic on unexpected input. regexp.MustCompile is
an obvious example. I actually can't think offhand of any other
examples... but it's also not unreasonable to implement features
similar to slice and map accesses (which also panic) in one's own data
types.
--
David Roundy
No, that's only true for some functions. The standard library does
have functions that panic on unexpected input. regexp.MustCompile is
an obvious example.
I actually can't think offhand of any other
examples...
but it's also not unreasonable to implement features
similar to slice and map accesses (which also panic) in one's own data
types.
func TestAPI_Fail(t *testing.T) {defer func(){assert.NotNil(t, recover())}()DoSomething("that-should-panic")}
func TestAPI_Fail(t *testing.T) {defer func(){err := recover()assert.IsType(t, error, err)assert.Equal(t, "Error message", err.(error).Error())}()DoSomething("that-should-panic")}