Alex Rivera | Logout

JUnit4 fail() is here, but where is pass()?

Asked 2010-10-27T17:53:43.770
98

There is a fail() method in JUnit4 library. I like it, but experiencing a lack of pass() method which is not present in the library. Why is it so?

I've found out that I can use assertTrue(true) instead but still looks unlogical.

@Test
 public void testSetterForeignWord(){
  try {
   card.setForeignWord("");
   fail();
  } catch (IncorrectArgumentForSetter ex){
  }

 // assertTrue(true);
 }
Edit
Report

1 Answer

3

There is no need for the pass method because when no AssertionFailedException is thrown from the test code the unit test case will pass.

The fail() method actually throws an AssertionFailedException to fail the testCase if control comes to that point.

answered 2010-10-27T18:11:02.380

Your Answer