Prev Next

Testing / Junit Interview questions

Exception testing (Difference between Junit 3 and Junit 4)

Junit 3

 public void testGetElement() {
  try {
    (new ArrayList()).get(0);
    fail("The test should have failed");
  } catch (NullPointerException e) {
    assertTrue("Sanity check", true);
  }
}

Junit 4

Junit 4.x

@Test(expected = IndexOutOfBoundsException.class)
public void testGetElement() {
  (new ArrayList()).get(0);
}

More Related questions...

Show more question and Answers...


Comments & Discussions