gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
574 stars 38 forks source link

Use `t.Cleanup()` in constructor #62

Closed maratori closed 6 months ago

maratori commented 2 years ago

Now I have to remember to add defer or t.Cleanup in each test manually.

func TestSomething(t *testing.T) {
  formatterMock := NewFormatterMock(t)
  defer formatterMock.Finish()
  ...
}

or

func TestSomething(t *testing.T) {
  formatterMock := NewFormatterMock(t)
  t.Cleanup(formatterMock.Finish)
  ...
}

It would be great to do it automatically in mock constructor like gomock does. Of course only if it's go 1.14 or newer.

hexdigest commented 6 months ago

Hey @maratori

This is a really good proposal. It's available in v3.3.0. Please let me know if you find any issues with it.

Thank you!