title: usage of @Before in Junit Testing
body: <p><code>@Before</code> notation in JUnit Testing is needed because several tests need similar objects created before they can run. </p>
  
  <p>But I don't get the difference between instantiating an object before the testcase function as a global object and putting inside a <code>@Before</code>.</p>
  
  <p>For example, I am testing my chess program and I am testing if my Piece object moves to a correct place by doing :</p>
  
  <pre><code>public class PawnTest { //The Test Class itself
  
  Board board = new Board();
  
  @Test
  /**
   * Testing the right movement
   */
  public void correctMovementTest() {
      Pawn p1 = new Pawn(Player.UP);
      board.placePiece(4, 3, p1);
      board.movePieceTo(5, 3, p1);
      assertEquals(board.getPiece(5, 3), p1);
  }
  
  @Test
  /**
   * Testing the right movement
   */
  public void correctMovementTest2() {
      Pawn p1 = new Pawn(Player.UP);
      board.placePiece(4, 3, p1);
      board.movePieceTo(6, 3, p1);
      assertEquals(board.getPiece(6, 3), p1);
  }
  
  ....
  </code></pre>
  
  <p>So wouldn't it just work if I decalre <code>Board</code> and <code>Pawn</code> <code>p1</code> outside the testcase method? Why would we need <code>@Before</code> in the test class?</p>
  
  <p>Also, doing this won't work</p>
  
  <pre><code>@Before
  public void setup() {
      Board board = new Board();
      Pawn p1 = new Pawn(Player.UP);
  }
  </code></pre>
  
  <p>I thought this would actually set up the objects before the test cases so that I won't have to set them up on every test cases, but the test cases wouldn't actually read the p1 object and the board.</p>