How to mock in your Go tests - Golang Tutorial
HTML-код
- Опубликовано: 18 сен 2024
- Since the most asked feature this week was mocking, here I show you how you can take advantage of structs and interfaces to mock any artifacts you might be using.
GitHub repo: github.com/fed...
Hope you liked the video! If you did, please like and subscribe to get new videos as soon as I upload them!
If you want to go deeper into the language and other Software Engineering aspects: federicoleon.com/
Fede.
Came here wanting to learn go testing, came out learning everything is needed plus more!
Awesome video contains a lot more than what the video title says. Thank you!
keep up the good work bro, I support you
Brilliant!
great vid!
Thank you for the information!
you are the boss.
Thanks a lot for the video. But, as someone rightly pointed out I would want to see how I can mock string_utils function inside IsPalindrome() because in reality we will be writing test case for IsPalindrome() function which is our implementation. So, why bother mocking that? We have to mock it's dependencies right?
Great video. Minor nitpick - your isPalindrome function will fail for UTF string. When working with strings only range operator respects runes
great work , thank you.
great, thank you very much!!
Nice one
this is soo complicated and convoluted.. There's gotta be an easier way of doing this, no?
The mocking functionality of the testify package
Thanks for the video, but what we are trying to achieve here.
func TestIsPalindromeWithMock(t *testing.T) {
StringsService = &serviceMock{}
isPalindromeFunction = func(t string) bool {
return false
}
assert.False(t, StringsService.IsPalindrome("ana"))
isPalindromeFunction = func(t string) bool {
return false
}
assert.False(t, StringsService.IsPalindrome("ana"))
}
by doing this we are mocking the string_service? what we wanted is mocking the string_utils
Here, actually you are testing a mock method. Not actual method.