stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.53k stars 1.6k forks source link

Feat: added OnFunc to mock using method directly and MockCall to mock quick methods #1678

Open harvic3 opened 1 week ago

harvic3 commented 1 week ago

Summary

This PR introduces enhancements to the mocking library, allowing for more robust and refactor-friendly mocking of methods.

Changes

Examples

Previously, mocking a method required writing the method name as a string, which could lead to issues during renaming or refactoring. Additionally, mocking methods with multiple return values involved writing extensive conditional logic. The new functionalities simplify these processes significantly.

These enhancements make the mocking library easier to use and maintain, providing a more intuitive and error-resistant approach to mocking methods.

Motivation

After three weeks using golang I believe theese changes were necessary to improve the usability and maintainability of the mocking library. By allowing direct method references, we reduce the risk of errors during renaming or refactoring. The MockCall function simplifies the mocking process, making the code cleaner and easier to maintain. Observations and comments with the aim of improving the proposal will be well received because my only intention is to contribute to the evolution of the project.

Related issues

N/A