Home arrow static arrow Java Programming [Archive] - JUNIT assertEquals and assertTrue
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - JUNIT assertEquals and assertTrue
This topic has 2 replies on 1 page.

Posts:48
Registered: 6/11/03
JUNIT assertEquals and assertTrue  
Aug 6, 2004 10:56 PM



 
Hi all,

Anyone knows the underneath implementation of Assert.assertEquals and Assert.assertTrue?

The reason I'm asking this is that
I have a test that FAILED with Assert.assertTrue( str1 == str2 );
but PASSED with Assert.assertEquals( str1, str2 );

where str1 and str2 both contain hexcode.

Any suggestion or help is greatly appreciated. :)
Thank you in advance.

regards.
Sean

 

Posts:38
Registered: 03.07.04
Re: JUNIT assertEquals and assertTrue  
Aug 7, 2004 1:52 AM (reply 1 of 2)



 
Hello,

I think the first test should be Assert.assertTrue( str1.equals(str2))

Str1 == str2 will compare the references
Str1.equals(str2) will compare the content.
 

Posts:18,384
Registered: 21.03.00
Re: JUNIT assertEquals and assertTrue  
Aug 7, 2004 1:57 AM (reply 2 of 2)



 
I have a test that FAILED with Assert.assertTrue( str1
== str2 );
but PASSED with Assert.assertEquals( str1, str2 );

Hi,

You should really read about the differences between == and equals. They are not the same.

/Kaj
 
This topic has 2 replies on 1 page.