ovechkin-dm / mockio

Mockito for golang
MIT License
73 stars 2 forks source link

Default SetUp() eats panics #59

Closed HenrikPoulsen closed 5 months ago

HenrikPoulsen commented 5 months ago

I was refactoring some of my code and had some tests failing even though I had correctly updating them. It was complaining that the method I was mocking hasn't been called when I ran VerifyNoMoreInteractions().

Cause:
    expected num method calls: 1, got : 0
        Manager.CreateTemporaryToken(Exact(test), Exact(repo), Any[githubutils.GitHubClient], Exact(0))

Turns out that the code was panicking due to having forgotten to pass in a new mock to the constructor for the thing being tested. So I would have expected the panic to bubble up instead of being eaten.

For the tests I'm using

func TestSomething(t *testing.T) {
    SetUp(t)
        ...

Which is how the readme on this repo does it.

However if I change it to use the same reporter as the mockio tests

reporter := common.NewMockReporter(t)
SetUp(reporter)

Then I get

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x11019f1]

It would be nice if the default SetUp(t) behaved more like the mock reporter so that one doesn't have to add it to every single test manually

ovechkin-dm commented 5 months ago

Hi, can you please provide minimal reproducible example for it?

HenrikPoulsen commented 5 months ago

Hey, sorry for the slow reply. I found this issue when I was doing some heavy refactoring and sadly didn't think to look closer at how it was setup. I tried reproducing it at a later time, but didn't manage. I will close this ticket for now, if I do see it again I'll setup a repro immediately. Sorry for the noise