I personally go with 3.

If you have just one function private function you would like to test, you
can also make it public but add "@doc false" so it doesn't show when
generating documentation and so on.



*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Thu, May 19, 2016 at 5:20 PM, Eric Merritt <[email protected]> wrote:

> Guys,
>
> How do we test internal functions? To give you background, we go through a
> lot of effort to make sure we split the functions in our modules into side
> effect free and side effect full functions. In Erlang, at least, we test
> the side effect free functions using things like eunit and quick check. For
> the side effect full functions we stand up the system and run integration
> tests. We can do that cheaply as we spent a lot of effort to make sure our
> systems can be stood up as needed.
>
> The problem is that the side effect full functions tend to be the external
> api of the module and declared with 'def'. While the side effect free
> functions tend to be internal and declared with `defp`. The common response
> is to use mocking and just test the external api, the internal api will get
> tested as a side effect. We don't use mocking unless its mocking a service.
> I wrote up why at one point and that write up is easy to find, so I don't
> want to argue the validity of the approach here.
>
> So that brings up how we go about it solving this testing problem. I can
> think of three possible ways to do that.
>
> 1) Just use `def` instead of `defp` and document what the external
> functions are -- Problematic for a number of reasons
> 2) Write a macro that looks at an environment variable and, if we are in
> test exposes everything -- Our test and prod systems would look
> significantly different though
> 3) Split all of our modules into API modules and internal modules -- This
> is what we do in Haskell and probably the least invasive approach.
>
> I wonder if there are elixir specific pros and cons here I should be aware
> of, alternatives? etc.
> Eric
>
> Sent from ProtonMail <https://protonmail.com>, encrypted email based in
> Switzerland.
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-talk/z8nxswLVL4YJHzzmtqkycd8CvrzNNAZGi2F5QCig1X_VpOLCB69OgFm5suhoiVvYpPOkYr83rn8RgRwFqculxg%3D%3D%40merritt.tech
> <https://groups.google.com/d/msgid/elixir-lang-talk/z8nxswLVL4YJHzzmtqkycd8CvrzNNAZGi2F5QCig1X_VpOLCB69OgFm5suhoiVvYpPOkYr83rn8RgRwFqculxg%3D%3D%40merritt.tech?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-talk/CAGnRm4LyJChjG9zEkOVUHpvX%2BWzmN29g%2BZpBXwUV9v65P%3D3QPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to