title: Junit - Null Pointer Exception with @Before
body: <p>I just started learning Junit and I just got Null Pointer Exception in my first test. </p>
  
  <p>If I read correctly <code>@Before</code> annotation means it will be called before each test but looks like it doesn't or something else is wrong with this code. In this code below I get Null Pointer in <code>myList.add()</code> line.</p>
  
  <pre><code>import org.junit.Before;
  import org.junit.jupiter.api.Test;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import static org.junit.Assert.*;
  
  public class StudentTest {
      private List&lt;String&gt; myList;
  
      @Before
      public void init(){
          myList = new ArrayList&lt;&gt;();
      }
      @Test
      public void size(){
          myList.add("TEST");
          assertEquals(1, myList.size());
      }
  }
  </code></pre>