JUnit assertFalse example

Junit 5’s org.junit.jupiter.Assertions class provides different static assertions method to write test cases.

Please note that you need to use JUnit’s org.junit.Assert class in case of JUnit 4 or JUnit 3 to assert using assertFalse method.

Assertions.AssertFalse() checks if supplied boolean condition is false. In case, condition is true, it will through AssertError.

public static void assertFalse(boolean condition)
public static void assertFalse(boolean condition, Supplier messageSupplier)
public static void assertFalse(BooleanSupplier booleanSupplier)
public static void assertFalse(BooleanSupplier booleanSupplier, String message)
public static void assertFalse(boolean condition,String message)
public static void assertFalse(BooleanSupplier booleanSupplier,Supplier messageSupplier)

Here is simple example

When you run above testcase, you will get below output:
AssertFalseTestOutput

Let’s understand output of each testcase:


palindormeTestwithCondition – Pass

As “ADAM” is not palindrome, so this testcase will pass.


palindormeTestwithConditionAndMessage – Fail

As “MADAM” is palindrome, so this testcase will fail.


palindormeTestWithBooleanSupplier – Pass

As “ASDAS” is not palindrome, so this testcase will pass.


palindormeTestWithConditionAndSupplier – Fail

As “LEVEL” is palindrome, so this testcase will fail.


palindormeTestWithBooleanSupplierAndMessage – Pass

As “PLAN” is not palindrome, so this testcase will pass.


palindormeTestWithBooleanSupplierAndSupplier – Fail

As “RADAR” is palindrome, so this testcase will fail.


That’s all about Assertions.assertFalse()

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *