In the previous example we explain how to use of assertEquals assertion method, in this example we try to illustrates about how to use the 'assertNotEquals' assertion method to test whether the class file executed test cases successfully or not.
The assertNotEquals assertion method is used to compare between two variable whether both are equal or not, if both 'expected' and 'actual' are equal then the AssertionError Exception throw the following error:
[junit] Testsuite: AssertNotEqualsExample
[junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.062 sec
[junit]
[junit] Testcase: test(AssertNotEqualsExample): FAILED
[junit] expected not equals to: <2>
[junit] junit.framework.AssertionFailedError: expected not equals to: <2>
[junit] at junitx.framework.Assert.failNotEquals(Assert.java:354)
[junit] at junitx.framework.Assert.assertNotEquals(Assert.java:132)
[junit] at junitx.framework.Assert.assertNotEquals(Assert.java:248)
[junit] at junitx.framework.Assert.assertNotEquals(Assert.java:257)
[junit] at AssertNotEqualsExample.test(Unknown Source)
[junit]
[junit]
[junit] Test AssertNotEqualsExample FAILED
but if both are not equal then the program executed test case successfully. In this example build.xml file is used to compile, test and run the java file.
build.xml
<project name="JUnitTest" default="test" basedir=".">
|
Source Code of AssertNotEqualsExample.java
import java.lang.*;
|
output:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JUnit Test 'assertNotEquals' Example Using Ant
Post your Comment