<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="54051" data-post-id="54051">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cmkarlsson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/120/23000_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cmkarlsson
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I very much oppose making functionality public just because it needs testing.</p>
<p>I guess the reasoning from doing this is that it is only the public APIs that matter any way. This shines though in elixir documentation as well which only works for public functions (at least I think it still does)</p>
<p>Yes, you should test and document your public APIs, they are for the users of your module. But I think you should test and document the private functions as well. They are for the developers of the module. Just different audience.</p>
<p>I find myself having quite complicated private functions doing implementing the public API and it doesn’t make sense to make them public at all. You just want to make sure they are well tested. Not from an API point of view but because of implementation.</p>
<p>I do use the <code>export_all</code> directive, and generally in erlang I like to have the private testing done in the same module using eunit. I miss having the test code close a bit in elixir.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54051" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-54051" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54051"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="54054" data-post-id="54054">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cmkarlsson" data-post="12" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/48/23000_2.png" class="avatar"> cmkarlsson:</div>
<blockquote>
<p>I do use the export_all directive, and generally in erlang I like to have the private testing done in the same module using eunit. I miss having the test code close a bit in elixir.</p>
</blockquote>
</aside>
<p>This exactly, that is why I put test functions in my modules that only exist at <code>Mix.env == :test</code> time.  I guess that is the point of doctests now though, I use a <em>lot</em> of doctests just to keep them in-module.  ^.^;</p>
<p>Doctests are awesome though.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54054" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-54054" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54054"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="54214" data-post-id="54214">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="eahanson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/eahanson/120/20895_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  eahanson
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>One thing to watch out for is that when you disable the private-ness of a function in the test env, you’re not just allowing your tests to access private functions, you’re letting <em>all</em> your code access <em>all</em> private functions, so if you have some code that is accidentally calling a private function, your test suite won’t catch the error.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54214" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-54214" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54214"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="54225" data-post-id="54225">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bobbypriambodo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bobbypriambodo/120/2843_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bobbypriambodo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="polypush135" data-post="3" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/p/9dc877/48.png" class="avatar"> polypush135:</div>
<blockquote>
<p>but then why have any private methods</p>
</blockquote>
</aside>
<p>I definitely wasn’t suggesting that. Just that in your case it just makes sense to me to separate it. <a class="mention" href="/u/lostkobrakai" rel="nofollow">@LostKobrakai</a> sounded my opinions nicely.</p>
<aside class="quote no-group" data-username="polypush135" data-post="6" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/p/9dc877/48.png" class="avatar"> polypush135:</div>
<blockquote>
<p>My only hesitation for extraction was that nothing else in my app (“with exception to my test”) needed that method.</p>
</blockquote>
</aside>
<p>But your test is using that method (function) nevertheless, so (again, for me) it just makes sense to make it public. Then again, this is probably the flaw of languages that only have two access modifiers. In Java, for example, I can just define the method package-private and let the test be in the same package, therefore giving access to all methods necessary. Yeah, I can’t believe I just compared Elixir to Java either.</p>
<p>By separating that function into another module, basically you get:</p>
<ol>
<li>Separation of concerns</li>
<li>The ability to call the encrypt function from test, which means you don’t need to jump hoops</li>
<li>The ability to create a mock of the Encryption module (e.g. via the amazing <a href="https://hexdocs.pm/mox/Mox.html" rel="noopener nofollow ugc">Mox</a> library) if you don’t actually care about the implementation of the encrypt function</li>
</ol>
<p>That indeed introduce the cost of indirection and opening possibilities of other modules “accidentally” calling that function. But yeah, most libraries I’ve seen in languages like this usually just define an <code>Internal</code> modules with big warnings that you shouldn’t depend on them, while still actually <em>allowing</em> others to access it. A trade-off that you need to weigh.</p>
<aside class="quote no-group" data-username="cmkarlsson" data-post="12" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/48/23000_2.png" class="avatar"> cmkarlsson:</div>
<blockquote>
<p>I very much oppose making functionality public just because it needs testing.</p>
</blockquote>
</aside>
<p>I wholeheartedly agree.</p>
<aside class="quote no-group" data-username="cmkarlsson" data-post="12" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/48/23000_2.png" class="avatar"> cmkarlsson:</div>
<blockquote>
<p>Yes, you should test and document your public APIs, they are for the users of your module. But I think you should test and document the private functions as well. They are for the developers of the module. Just different audience.</p>
</blockquote>
</aside>
<p>This too. It makes sense to test internal implementations, although I can see the test code would definitely change a lot as implementation changes, but not necessarily a thing you need to avoid. Btw, OP wants to <em>use</em> the private function, not test it, I don’t know if that makes a difference <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>–</p>
<p>There was also this proposal thread (in which the package <code>private</code> was mentioned):</p>
<p><a href="https://forum.elixirforum.com/t/proposal-docp-for-private-function-documentation-and-doctests/3732" rel="nofollow">https://forum.elixirforum.com/t/proposal-docp-for-private-function-documentation-and-doctests/3732</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54225" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-54225" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54225"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="54226" data-post-id="54226">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sasajuric" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/120/991_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sasajuric
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Elixir In Action</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cmkarlsson" data-post="12" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/48/23000_2.png" class="avatar"> cmkarlsson:</div>
<blockquote>
<p>But I think you should test and document the private functions as well.</p>
</blockquote>
</aside>
<p>I mostly disagree with this. In my experience private functions are mostly internal details of the implementation, and the main reason of their existence is to organize the module internal code and make it easier to follow.</p>
<p>The API of the module is what the module guarantees, and this is IMO the only thing that should be tested.</p>
<aside class="quote no-group" data-username="cmkarlsson" data-post="12" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/48/23000_2.png" class="avatar"> cmkarlsson:</div>
<blockquote>
<p>I find myself having quite complicated private functions doing implementing the public API and it doesn’t make sense to make them public at all. You just want to make sure they are well tested. Not from an API point of view but because of implementation.</p>
</blockquote>
</aside>
<p>In such cases, I find that there’s usually potential to split the module, and move complex internal functions as public functions of the new module, so they can be properly documented and tested.</p>
<p>Occasionally I do see the need to explain some private function, in which case I simply use a comment.</p>
<p>Finally, it’s worth noting that in Elixir, functions which are public but not meant to be invoked directly, should be marked with <code>@doc false</code>. This should indicate that a function is internal (even though marked public), and the clients should not depend on it directly. Such function will not appear in the generated doc, and the users will be unaware of its existence. People who read the code will see the function, but they will also see that it is marked with <code>@doc false</code>, and hence not meant to be invoked directly.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54226" data-batch-url="/posts/batch_likers">
                        6
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-54226" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54226"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="54245" data-post-id="54245">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="bobbypriambodo" data-post="15" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bobbypriambodo/48/2843_2.png" class="avatar"> bobbypriambodo:</div>
<blockquote>
<p>But your test is using that method (function) nevertheless, so (again, for me) it just makes sense to make it public.</p>
</blockquote>
</aside>
<p>Actually I often (mostly back in erlang days) made a function called <code>__tests__</code> that tested things in that module itself and it only existed at test time and was called by the testing framework.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54245" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-54245" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54245"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="54275" data-post-id="54275">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cmkarlsson" data-post="12" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/48/23000_2.png" class="avatar"> cmkarlsson:</div>
<blockquote>
<p>Yes, you should test and document your public APIs, they are for the users of your module. But I think you should test and document the private functions as well. They are for the developers of the module. Just different audience.</p>
</blockquote>
</aside>
<p>Most of the dissonance in these discussions come with the disagreement of what a private function means. To me, a private function is an implementation detail. I don’t care how it is named, I don’t care about the argument it receives. If I refactor my private functions and a test breaks, I have a bad test. This is also how the compiler is designed. A private function may not exist at all after the code is compiled.</p>
<p>That’s also why Elixir makes a distinction between code comments and documentation. Code comments are for those reading the source code.</p>
<p>In any case, if a private function has complexity to the point you feel you need to test it and/or document it, then it is most likely worth its own module. And you can still do so while keeping it private and using doctests. To provide an actual example, let’s see how the code above could be rewritten.</p>
<p>Let’s assume <a class="mention" href="/u/polypush135" rel="nofollow">@polypush135</a>’s code looks like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defmodule User.Invitation do
    def find_invite!(invite_token) do
      Repo.get_by!(User, invite_token: encrypt_token(invite_token))
    end

    defp encrypt_token(token) do
      :crypto.hmac(:sha256, BeffectWeb.Endpoint.config(:secret_key_base), token)
      |&gt; Base.encode16(case: :lower)
    end
  end
</code></pre>
<p>I would rewrite it to:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule User.Invitation do
  defmodule Token do
    @moduledoc false

    @doc """
    Now I can doctest this too!
    """
    def encrypt(token) do
      :crypto.hmac(:sha256, BeffectWeb.Endpoint.config(:secret_key_base), token)
      |&gt; Base.encode16(case: :lower)
    end
  end

  def find_invite!(invite_token) do
    Repo.get_by!(User, invite_token: Token.encrypt(invite_token))
  end
end
</code></pre>
<p>This way you keep everything in the same file, you provide a logical place for grouping all of the token functionality, you can write tests and doctests and you still don’t expose it to your “final” users.</p>
<p>PS: Note ex_doc now allows custom groups, so you can even have modules targeting different audiences and you can use the grouping functionality to break those apart in the UI.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54275" data-batch-url="/posts/batch_likers">
                        15
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-54275" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54275"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="54276" data-post-id="54276">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="polypush135" data-post="4" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/p/9dc877/48.png" class="avatar"> polypush135:</div>
<blockquote>
<p>I very much like this idea. I wonder what bad side effects could arise from this.</p>
</blockquote>
</aside>
<p><a class="mention" href="/u/eahanson" rel="nofollow">@eahanson</a> already pointed out that you can now have bugs that won’t be caught in tests. It is worth mentioning that <code>@compile :export_all</code> emits warnings from OTP 20 on:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">warning: export_all flag enabled - all functions will be exported
  lib/elixir/test/elixir/code_formatter/general_test.exs:3
</code></pre>
<p>FWIW, the warning and functionality comes from the Erlang compiler, Elixir has nothing to do with it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54276" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-54276" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54276"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="54297" data-post-id="54297">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cmkarlsson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/120/23000_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cmkarlsson
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="18" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Most of the dissonance in these discussions come with the disagreement of what a private function means. To me, a private function is an implementation detail. I don’t care how it is named, I don’t care about the argument it receives. If I refactor my private functions and a test breaks, I have a bad test.</p>
</blockquote>
</aside>
<p>Yes, we are likely arguing semantics. I agree here to. Private functions are for implementation detail, I don’t care how they are named. And if an “interface test” breaks if I refactor a private function then it is a bad test.</p>
<p>But I feel that in a number of cases the implementation detail also needs to be tested and I don’t want these test mingled with my other testing because they test different things.</p>
<p>You have a good suggestion to lift this out into a “private” module and that seems like a good solution. I don’t see this as much different than having a “private” section of the same module though, except than perhaps it is a better fit for how elixir do things.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54297" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-54297" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54297"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="54298" data-post-id="54298">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cmkarlsson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/120/23000_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cmkarlsson
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sasajuric" data-post="16" data-topic="9281">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/48/991_2.png" class="avatar"> sasajuric:</div>
<blockquote>
<p>The API of the module is what the module guarantees, and this is IMO the only thing that should be tested.</p>
</blockquote>
</aside>
<p>Different sort of tests. Yes, the API tests are the most important. They are there to make sure you don’t break the contract of your public API, but I think it is a very bad idea to test implementation detail here. Your users don’t care about implementation detail and I don’t think these tests should either. But the implementation has to be tested somewhere.</p>
<p>Perhaps it is more idomatic in elixir to lift this out into a “private” module as <a class="mention" href="/u/josevalim" rel="nofollow">@josevalim</a> suggests but for me this is the same concept as having privates tests. Just a different implementation.[quote=“sasajuric, post:16, topic:9281”]<br>
Finally, it’s worth noting that in Elixir, functions which are public but not meant to be invoked directly, should be marked with <a class="mention" href="/u/doc" rel="nofollow">@doc</a> false. This should indicate that a function is internal (even though marked public), and the clients should not depend on it directly. Such function will not appear in the generated doc, and the users will be unaware of its existence. People who read the code will see the function, but they will also see that it is marked with <a class="mention" href="/u/doc" rel="nofollow">@doc</a> false, and hence not meant to be invoked directly.<br>
[/quote]</p>
<p>Thanks, I wasn’t aware of this option</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="54298" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/tests-that-rely-on-private-methods/9281/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-54298" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="54298"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/9281/load_more?page=3">Load more posts (1 remaining)</a>
</div></template></turbo-stream>