Is there a way to test private functions in modules in ExUnit of Elixir?

Noah Blues picture Noah Blues · Jan 6, 2014 · Viewed 7.5k times · Source

Functions defined by defp aren't exported so I can't execute them in places other than in the module.

Answer

José Valim picture José Valim · Jan 6, 2014

No, there is no way to test them via ExUnit.

I personally avoid testing private functions because usually you end up testing implementation instead of behaviour and those tests fail as soon as you need to change the code. Instead, I test the expected behaviour via the public functions, breaking them in small, consistent chunks.