Home » Core Java » junit » JUnit assertFalse example

About Alvin Reyes

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.

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.

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
(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of