How to test what happens in a function deep in the call stack

I was wondering how I could improve tests for certain packages of mine, let’s take Makie as an example. Makie turns input data to output images but only testing reference images is not satisfactory. We have lots of internal functions that are worth testing, however often it’s reasonably annoying to create the input data they need, as those are usually prepared by pipeline functions further upstream. And we don’t want to copy pipeline implementation into the tests, because that’s a source for errors.

So my question is, if I have functions f, g, h which call each other, but h returns to g and g to f, and the output of f is not of interest. How can I test the output of h given some input for f? Like temporarily overwriting h with a special version that I can grab the output of.

1 Like

It seems like some kind of mocking might be appropriate here.

I never have used it in Julia, but this says it does what I mean:

1 Like

Yeah that looks very applicable, the main drawback seems to be that one has to apply @mock to all callsites one is interested in. I never really use packages meant for testing that require to instrument the actual source code

I found GitHub - JuliaTesting/SimpleMock.jl: A basic mocking module but it seems to be broken after 1.6 sadly