JUnit assertFalse example
1. Introduction
To follow through with my previous post about assertTrue, this will tackle about the exact opposite of that function. The assertFalse. The assertFalse is basically a function that can be used to check if a specific logic or process will return a false statement.
This can be in any conditional or structural logic that will return a boolean true or false. See the code example below.
2. The Source
JUnitAssertFalseExample.java
package com.areyes1.jgc.junit.assertfalse;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
public class JUnitAssertFalseExample {
int totalNumberOfApplicants = 0;
int totalNumberOfAcceptableApplicants = 10;
@Before
public void setData() {
this.totalNumberOfApplicants = 9;
}
@Test
public void testAssertFalseFalse() {
assertFalse((this.totalNumberOfApplicants != this.totalNumberOfAcceptableApplicants));
}
@Test
public void testAssertFalse() {
assertFalse((this.totalNumberOfApplicants == this.totalNumberOfAcceptableApplicants));
}
@Test
public void testAssertFalseWithMessage() {
assertFalse(
"Is total number of applicants acceptable?",
(this.totalNumberOfApplicants != this.totalNumberOfAcceptableApplicants));
}
}
The assertFalse is basically a function that can take any conditional statement that can either return a boolean (true or false). Developers can use it to test negative impacts and black box testing schemes.
Running this example will give you an output in Eclipse.

3. Download the Eclipse project
This was an example about JUnit assertFalse.
You can download the full source code of this example here: junit-assertfalse-example


