junit

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

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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.

Figure 1.0 Example of assertFalse
Figure 1.0 Example of assertFalse

3. Download the Eclipse project

This was an example about JUnit assertFalse.

Download
You can download the full source code of this example here: junit-assertfalse-example

Alvin Reyes

Alvin has an Information Technology Degree from Mapua Institute of Technology. During his studies, he was already heavily involved in a number of small to large projects where he primarily contributes by doing programming, analysis design. After graduating, he continued to do side projects on Mobile, Desktop and Web Applications.
Subscribe
Notify of
guest


This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button