X-Received: by 2002:ae9:ea0f:: with SMTP id f15mr717757qkg.55.1553169501394; Thu, 21 Mar 2019 04:58:21 -0700 (PDT) X-Received: by 2002:a81:1943:: with SMTP id 64mr2650393ywz.355.1553169501167; Thu, 21 Mar 2019 04:58:21 -0700 (PDT) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!h4no3308968qtn.0!news-out.google.com!d8ni1330qtr.1!nntp.google.com!h4no3308964qtn.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.help Date: Thu, 21 Mar 2019 04:58:20 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=182.23.155.2; posting-account=hs8HRwoAAAAxNW-x9J00SRYB_45MSaj5 NNTP-Posting-Host: 182.23.155.2 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <258bdfbc-1e89-493c-978d-62e0802284fa@googlegroups.com> Subject: Re: What is/are the difference(s) between assertSame and assertEquals in JUnit? From: onlyfullstackdev@gmail.com Injection-Date: Thu, 21 Mar 2019 11:58:21 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Lines: 55 Xref: csiph.com comp.lang.java.help:4256 assertEquals - It check the objects are equal or not based on the overridde= d equals() method of that class. So we can check the equality of object bas= ed on their state(compare the values of their instance variables). assertEquals() The assertEquals() method compares two objects for equality,= using their equals() method. @Test public void assertEquals_example() { Employee employeeNew =3D new Employee(); employee.setSalary(1000000.0); assertEquals("EMPLOYEE OBJECT", employee, employeeNew); } If the two objects are equal according to there implementation of their equ= als() method, the assertEquals() method will return normally. Otherwise, th= e assertEquals() method will throw an exception, and the test will stop the= re. assertSame() and assertNotSame() The assertSame() and assertNotSame() metho= ds tests if two object references point to the same object or not. It is no= t enough that the two objects pointed to are equals according to their equa= ls() methods. It must be exactly the same object pointed to. Here is a simple example: @Test public void assertSame_assertNoSame_example() { assertSame(employeeService.getEmployeeFromId(1), employeeService.getEmp= loyeeFromId(1)); assertNotSame(employee, employeeService.getEmployeeFromId(1)); // We wi= ll get null as response } You can follow below url to get more information: https://onlyfullstack.blo= gspot.com/2019/02/junit-assert-methods.html https://onlyfullstack.blogspot.com/2019/02/junit-tutorial.html On Thursday, August 7, 2008 at 1:53:11 AM UTC+8, RC wrote: > In JUnit Assert class have >=20 > assertSame(Object expect, Object actual) > and > assertEquals(Object expect, Object actual) >=20 > What is/are the difference(s)? >=20 > Interesting, there is >=20 > assertNotSame(Object expect, Object actual) >=20 > But there is no >=20 > assertNotEquals(Object expect, Object actual)