testify icon indicating copy to clipboard operation
testify copied to clipboard

suite: missing signature check before calling Test* method

Open wvell opened this issue 2 years ago • 5 comments

If a test method on a suite has a parameter there is a panic:

func (suite *SomeTestSuite) TestUpdateSomething(somearg string) {
......
}

When running this you get the following panic:

suite.go:87: test panicked: reflect: Call with too few input arguments
....

I think the error handling could be more clear here. Something like "method TestUpdateSomething on SomeTestSuite contains arguments"

Here is the go.dev link: https://go.dev/play/p/cNNfqH5QpeQ

I can create a pull request if this change is wanted?

Edit: Some more context. I run into this problem when I am porting old test methods to a suite.

wvell avatar Nov 16 '23 09:11 wvell

Please provide an example running on go.dev/play.

dolmen avatar Nov 19 '23 07:11 dolmen

I've added a go.dev example.

wvell avatar Nov 20 '23 08:11 wvell

This is definitely a dirty bug: Suite should check the method signature and report a test failure if the type doesn't match.

A PR would be welcome.

dolmen avatar Nov 22 '23 06:11 dolmen