Simplify embedded field access in generated mock constructors
Author: rengasCreated Apr 1, 2026Updated Apr 1, 2026
In the generated mock constructors, the code currently uses mock.Mock.Test(t) to register the testing interface:
func NewMyMock(t interface {
mock.TestingT
Cleanup(func())
}) *MyMock {
mock := &MyMock{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}Since Mock is an embedded field in the generated struct, Go promotes its methods automatically. The explicit mock.Mock.Test(t) is redundant and can be simplified to mock.Test(t):
mock.Test(t)This is a minor cleanup but aligns with Go idiomatic usage of embedded types, where accessing promoted methods directly is the standard practice.
Source: vektra/mockery