Home  >  Article  >  Java  >  assertEquals and assertNotEquals, use assertNotEquals with caution

assertEquals and assertNotEquals, use assertNotEquals with caution

黄舟
黄舟Original
2016-12-28 11:49:273535browse

When using

assertEquals(long actual, long expected) and assertNotEquals(**,**) in org.testng.Assert, pay attention to comparing the data types at both ends.

         

     

                provided in the Assert class        -   assertEquals supports: boolean double float int long Map Object byte[] byte char Coolection, etc. See API

for details assertNotEquals only supports three types: float double Object.

If an unsupported data type is used, Object will be called!

# For example:

    long long1 = 10L;
    long long2 = 10L;
// 以下 代码 全部通过,不会产生 assert 退出;
    Assert.assertEquals(long1, long2); //Assert.assertEqualslong,long)
    Assert.assertEquals(long1, 10); //Assert.assertEquals(long,long)
    Assert.assertNotEquals(long1, 10);//Assert.assertNotEquals(Object,Object)
    Assert.assertNotEquals(long2, 10); //Assert.assertNotEquals(Object,Object)
    
    Assert.assertNotEquals(long2, 9);//Assert.assertNotEquals(Object,Object)

and above are Assertequals and Assertnotequals. Use the content of assertnotequals carefully. For more related content, please pay attention to PHP Chinese (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn