The difference between assertEquals and assertSame methods in JUnit
Dec 28, 2016 am 11:40 AM1) The number of interfaces provided is not exactly the same.
assertEquals supports boolean, long, int and other java primitiveType variables.
assertSame only supports Object.
2) The comparison logic is different, and the results may be different.
assertSame is a direct comparison of objects. assertEquals can use the comparison logic provided by the compared object to perform comparisons.
Under the same conditions, the running results of the two are not necessarily the same.
A brief explanation is as follows:
The comparison logic of assertEquals(Object A, Object B):
If A and B are both Null, return true. Otherwise, call A.equals(B) to determine.
Comparison logic of assertSame(Object A, Object B):
Judged by the result of A == B operation.
The difference between A.equals(B) and A==B is.
If A does not override the equals method of java.lang.Object,
Then the memory address comparison of the two java objects will be the same as the result of A==B.
If A overrides the equals method (such as GregorianCalendar, BigDecimal class),
The result of the comparison may not be the same as the result of A==B.
The above are the different contents of the assertEquals and assertSame methods in JUnit. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot tools Tags

Hot Article

Hot tools Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How are annotations used for test methods in the JUnit framework?

Usage of JUnit unit testing framework in multi-threaded environment

JUnit Unit Testing Framework: A Beginner's Tutorial

JUnit unit testing framework: advantages and limitations of using it

Application of JUnit unit testing framework in Spring projects

What are the best practices for JUnit unit testing framework in Java?

JUnit unit testing framework: A guide to solving common memory leak problems

JUnit unit testing framework: Tips for running test cases in debug mode
