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.

Комментарии • 17

  • @hamiltonchevez8114
    @hamiltonchevez8114 4 года назад +1

    Came here wanting to learn go testing, came out learning everything is needed plus more!

  • @TenderBug
    @TenderBug 4 года назад

    Awesome video contains a lot more than what the video title says. Thank you!

  • @AgoestriHariyanto
    @AgoestriHariyanto 4 года назад

    keep up the good work bro, I support you

  • @ioannissavvidis3696
    @ioannissavvidis3696 2 года назад

    Brilliant!

  • @funnyhere
    @funnyhere 3 года назад

    great vid!

  • @MrMattdennis
    @MrMattdennis 4 года назад

    Thank you for the information!

  • @guptaachin
    @guptaachin 4 года назад

    you are the boss.

  • @ramdittakavi
    @ramdittakavi 3 года назад +1

    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?

  • @georgiyyamov5827
    @georgiyyamov5827 3 года назад

    Great video. Minor nitpick - your isPalindrome function will fail for UTF string. When working with strings only range operator respects runes

  • @AmolGautam
    @AmolGautam 4 года назад

    great work , thank you.

  • @maei1140
    @maei1140 4 года назад

    great, thank you very much!!

  • @СохибЕкубов
    @СохибЕкубов 4 года назад

    Nice one

  • @mistertwister8500
    @mistertwister8500 3 года назад +1

    this is soo complicated and convoluted.. There's gotta be an easier way of doing this, no?

    • @z.m.4331
      @z.m.4331 3 года назад

      The mocking functionality of the testify package

  • @sajithp2453
    @sajithp2453 4 года назад

    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

  • @pravinranjan
    @pravinranjan 3 года назад

    Here, actually you are testing a mock method. Not actual method.