You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing Unit Tests, I want to be able to mock out the external dependencies but couldn't find a way of doing this without introducing additional logic to the production code or using lambdas. Here is an example:
Suppose that I want to mock out external_function_needs_to_be_mocked during tests, in other languages where you have Traits and Interfaces, mocking this is pretty trivial but since there are no interfaces in Move, this is not an option.
Even a macro like #[not(test_only)] would've solved this but it's also not there. What I ended up doing is taking out the implementation to a separate function which gets all the functions from some_module as lambda functions:
This way, the test function is able to mock the necessary function however it likes but still, this is far from ideal. I really hope there is a sane way of dealing these kind of situations easily.
What error, if any, are you getting?
No response
What have you tried or looked at? Or how can we reproduce the error?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Discord user ID
No response
Describe your question in detail.
When writing Unit Tests, I want to be able to mock out the external dependencies but couldn't find a way of doing this without introducing additional logic to the production code or using lambdas. Here is an example:
Suppose that I want to mock out
external_function_needs_to_be_mocked
during tests, in other languages where you have Traits and Interfaces, mocking this is pretty trivial but since there are no interfaces in Move, this is not an option.Even a macro like
#[not(test_only)]
would've solved this but it's also not there. What I ended up doing is taking out the implementation to a separate function which gets all the functions fromsome_module
as lambda functions:This way, the test function is able to mock the necessary function however it likes but still, this is far from ideal. I really hope there is a sane way of dealing these kind of situations easily.
What error, if any, are you getting?
No response
What have you tried or looked at? Or how can we reproduce the error?
No response
Which operating system are you using?
Linux (Ubuntu, Fedora, Windows WSL, etc.)
Which SDK or tool are you using? (if any)
N/A
Describe your environment or tooling in detail
No response
Beta Was this translation helpful? Give feedback.
All reactions