title: Should I check implementation details or use class public API only in a unit test?
body: <p>Consider the following example:</p>
  <pre><code>public class Foo {
  
      protected List&lt;Integer&gt; arr = new ArrayList&lt;&gt;();
  
      void add(int i) { arr.add(i); }
  
      int size() { return 0; }
  }
  
  public class FooTest {
  
      Foo foo = new Foo();
  
      @Test
      void checkAdd() {
          foo.add(1);
          assertEquals(1, foo.size()); // fail
          assertEquals(1, foo.arr.size()); // pass
      }
  }
  </code></pre>
  <p>Sorry, I have a lame question but still unable to find an answer. Is it considered as a bad practice to check implementation details as a part unit testing? Obviously testing one part of public API via another part of public API may (and most likely will) lead to incorrect results. On the other side implementation can be very complicated, just imagine if you want to test HashMap.</p>