AssertNotEqual
AssertNotEqual is a unit testing assertion used to verify that two values are not equal. It passes when the two values differ and fails when they are equal. The assertion is commonly provided as a method such as assertNotEqual(a, b, msg=None) on a test case object. The exact syntax and name can vary by framework, but the core idea is to enforce inequality between two expressions.
The operation typically relies on the language’s equality operator, using a != b or an equivalent comparison.
- In Python's unittest framework, you would write: self.assertNotEqual(a, b) or self.assertNotEqual(a, b, msg="custom failure message"). If
- In other frameworks, the same concept is available under a similar name, sometimes with slight naming
- The result depends on the objects’ equality semantics. If a and b are objects with custom __eq__
- AssertNotEqual is most appropriate when a test specifically requires two values to differ, such as ensuring
Related assertions include assertEqual, which tests for equality, and specialized variants like assertNotAlmostEqual for numeric values