JUnit 5 assertNotEquals Example

In this article, we will learn about assertNotEquals() static method which belongs to JUnit 5 org.junit.jupiter.api.Assertions Class. Note that in JUnit 5 all JUnit 4 assertion methods are moved to org.junit.jupiter.api.Assertions class.
There are many overloaded version of assertNotEquals() methods present in org.junit.jupiter.api.Assertions class.
Let me list out tools and technologies that I have used to develop JUnit 5 assertNotEquals Example.

Tools and Technologies Used

  1. Eclipse photon (only this eclipse version supports JUnit 5)
  2. Maven
  3. JUnit 5
  4. JDK 8 or late
assertNotEquals(Object unexpected, Object actual) method asserts that two objects are not equals. If they are, an AssertionError without a message is thrown. If unexpected and actual are null, they are considered equal.

assertNotEquals() Method Example

package com.javaguides.junit5.assertions;

import static org.junit.Assert.assertNotEquals;

import org.junit.jupiter.api.Test;

/**
 * JUnit5AssertNotEqualsExample
 * @author javaguides.net
 *
 */
public class JUnit5AssertNotEqualsExample {
 public static String method1() {
  return null;
 }

 public static String method2() {
  return "Ramesh";
 }
 
 public static String method3() {
  return "Fadatare";
 }
 
 @Test
 public void assertNotEqualsTest() {
  assertNotEquals("null", method1());
  assertNotEquals("ramesh", method2());
  assertNotEquals("fadatare", method3());
 }
}

Output

Comments