v3 Release¶
Mockery releases version 3 of the project that provides a number of high-profile benefits over v2:
- Allows generation of
matryer
-style templates. The https://github.com/matryer/moq project is being subsumed into mockery to combine the speed and configuration flexibility of mockery with the simplicity of moq-style mocks. - Changes the generation scheme to be entirely driven off of Go templates. This means that the data provided to templates is considered as part of the public API.
- Mockery now allows users to specify their own templates to make code generation far easier. Mockery handles the problem of parsing source code and enables you to focus on creating your own interface implementations.
- Shedding all deprecated variables and simplifying the way in which mocks are configured.
Migration¶
Mockery-style mocks¶
In v3, mockery is capable of producing two styles of mocks. In v3, the mockery-style mocks are called testify
and can be used by setting template: testify
. The shape of the mocks should be identical (minus the now-required expecter methods) and should not require any changes to existing tests using testify-style mocks.(1)
- If this is not the case and the v3
testify
-style mocks have breaking changes, please submit an issue on Github.
Deprecation Warnings¶
Mockery v2 has explicitly deprecated a number of variables. These deprecations can be found here: https://vektra.github.io/mockery/latest-v2/deprecations/. Mockery logs warnings such as:
20 Jan 25 15:53 CST WRN DEPRECATION: disable-version-string will be permanently set to True in v3 deprecation-name=disable-version-string url=https://vektra.github.io/mockery/v0.0/deprecations/#disable-version-string version=v0.0.0-dev
20 Jan 25 15:53 CST WRN DEPRECATION: issue-845-fix must be set to True to remove this warning. Visit the link for more details. deprecation-name=issue-845-fix url=https://vektra.github.io/mockery/v0.0/deprecations/#issue-845-fix version=v0.0.0-dev
20 Jan 25 15:53 CST WRN DEPRECATION: resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False. deprecation-name=resolve-type-alias url=https://vektra.github.io/mockery/v0.0/deprecations/#resolve-type-alias version=v0.0.0-dev
20 Jan 25 15:53 CST WRN DEPRECATION: with-expecter will be permanently set to True in v3 deprecation-name=with-expecter url=https://vektra.github.io/mockery/v0.0/deprecations/#with-expecter version=v0.0.0-dev
These warnings provide doc URLs that indicate how to fix the warning to prepare for the v3 release. While we provide these warnings on a best-effort basis, they are unlikely to be comprehensive due to the large number of changes that v3 introduces. Please submit an issue on Github if you notice a missing deprecation warning that would be useful to have.
Layouts¶
In v2, mockery defaulted to placing mocks in a separate mocks/
directory as shown here. In v3, mockery will by default place mocks adjacent to the mocked interface.
It is still possible to place mocks in a separate directory by making use of the template variables and functions available to the configuration parameters.
Function Mocks¶
Mockery v2 allowed generating mocks for function types. v3 no longer does this as it provided little benefit for users.
Parameters¶
inpackage: True
¶
Mockery v2 has an inpackage
parameter that informed mockery when a mock was being generated in the same package as the original interface. In v3, this parameter has been removed as mockery is now able to detect when the mock is placed in the same package.
keeptree: True
¶
Mockery v2 provided a keeptree
parameter that was deprecated and used only in the pre-packages
config schema. This parameter has no use in v3 and has been removed.
replace-type:
¶
The replace-type:
parameter has an updated schema. In v2, users provided a list of strings, where each string needed to confirm to a specific format that was parsed at runtime. In v3, the schema is more explicit to make it simpler.
struct-name:
¶
The struct-name
parameter has been replaced with mock-name
.
resolve-alias:
¶
In v2, resolve-alias
was set to True
by default to retain backwards compatability. In v3, this is set to False
by default.
with-expecter:
¶
In v3, this parameter has been removed. testify
-style mocks will always generate expecter methods.
unroll-variadic:
¶
This parameter has been moved under the template-data:
parameter. Parameters that apply only to specific templates are not expressed in the top-level schema and are instead passed through the schemaless template-data:
map.
exclude:
¶
This parameter in v2 was renamed to exclude-subpkg-regex:
.