Help the world stop coronavirus! Stay home!

Prev Next

JUnit / 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);
}

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Junit Interview questions III

Comments & Discussions