Friday, 13 March 2020

TesNG: assertNotEquals: Check inequality

'assertNotEquals' method is used to check inequality of two elements. It is available in below forms.
public static void assertNotEquals(Object actual1, Object actual2, String message)
public static void assertNotEquals(Object actual1, Object actual2)
static void assertNotEquals(String actual1, String actual2, String message)
static void assertNotEquals(String actual1, String actual2)
static void assertNotEquals(long actual1, long actual2, String message)
static void assertNotEquals(long actual1, long actual2)
static void assertNotEquals(boolean actual1, boolean actual2, String message)
static void assertNotEquals(boolean actual1, boolean actual2)
static void assertNotEquals(byte actual1, byte actual2, String message)
static void assertNotEquals(byte actual1, byte actual2)
static void assertNotEquals(char actual1, char actual2, String message)
static void assertNotEquals(char actual1, char actual2)
static void assertNotEquals(short actual1, short actual2, String message)
static void assertNotEquals(short actual1, short actual2)
static void assertNotEquals(int actual1, int actual2, String message)
static void assertNotEquals(int actual1, int actual2)
public static void assertNotEquals(float actual1, float actual2, float delta, String message)
public static void assertNotEquals(float actual1, float actual2, float delta)
public static void assertNotEquals(double actual1, double actual2, double delta, String message)
public static void assertNotEquals(Set<?> actual, Set<?> expected)
public static void assertNotEquals(Set<?> actual, Set<?> expected, String message)
public static void assertNotEquals(Map<?, ?> actual, Map<?, ?> expected)
public static void assertNotEquals(Map<?, ?> actual, Map<?, ?> expected, String message)
public static void assertNotEquals(double actual1, double actual2, double delta)

AssertNotEqualsTest.java
package com.sample.app.assertions;

import static org.testng.Assert.assertNotEquals;

import org.testng.annotations.Test;

public class AssertNotEqualsTest {
 @Test
 public void test1() {
  assertNotEquals(2, 3);
 }

 @Test
 public void test2() {
  assertNotEquals(2, 2, "2 is equal to 2");
 }
}

Run AssertNotEqualsTest.java, you will get below messages in console.

[RemoteTestNG] detected TestNG version 7.0.0
FAILED: test2
java.lang.AssertionError: 2 is equal to 2 did not expect to find [2] but found [2]
 at org.testng.Assert.fail(Assert.java:97)
 at org.testng.Assert.assertNotEquals(Assert.java:1401)
 at com.sample.app.assertions.AssertNotEqualsTest.test2(AssertNotEqualsTest.java:15)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
 at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
 at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
 at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
 at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
 at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
 at java.util.ArrayList.forEach(ArrayList.java:1257)
 at org.testng.TestRunner.privateRun(TestRunner.java:770)
 at org.testng.TestRunner.run(TestRunner.java:591)
 at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
 at org.testng.SuiteRunner.run(SuiteRunner.java:304)
 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
 at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
 at org.testng.TestNG.runSuites(TestNG.java:1032)
 at org.testng.TestNG.run(TestNG.java:1000)
 at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
===============================================


Previous                                                    Next                                                    Home

No comments:

Post a Comment