You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Mark Hindess <ma...@googlemail.com> on 2006/04/15 22:38:52 UTC

assertEquals in tests with incorrect argument order

Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
quite confusing.  If you get the arguments to assertEquals the wrong
way around you get errors like:

  error expected <actual> but got <expected>

rather than:

  error expected <expected> but got <actual>

The correct way around is to have the expected value before the actual value.
We should all try make sure we get the arguments to assertEquals in the
correct order.  And fix any we spot that are the wrong way around. ;-)

I've fixed a few of the more obviously incorrect method calls in
HARMONY-353.

Regards,
 Mark.

--
Mark Hindess <ma...@googlemail.com>
IBM Java Technology Centre, UK.

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: assertEquals in tests with incorrect argument order

Posted by Richard Liang <ri...@gmail.com>.
Mark Hindess wrote:
> Another type of test that could be improved are those using
> assertTrue to compare two objects for equality.  Most of them should
> be using assertEquals, assertNull or assertNotNull.
>
> Using assertEquals automatically gives more meaningful error messages.
>   
I strongly support this idea. We should always try our best to make our 
test cases give meaningful message. :-)
> It saves people writing asserts like:
>
>   assertTrue("Size should return 100, returned: " + map.size(),
>              map.size() == 100);
>
> when this would do just as well:
>
>   assertEquals("Incorrect size", 100, map.size());
>
> I'm going to submit a few (big) patches to fix some of these.
>
> Regards,
>  Mark.
>
> On 4/15/06, Mark Hindess <ma...@googlemail.com> wrote:
>   
>> Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
>> quite confusing.  If you get the arguments to assertEquals the wrong
>> way around you get errors like:
>>
>>   error expected <actual> but got <expected>
>>
>> rather than:
>>
>>   error expected <expected> but got <actual>
>>
>> The correct way around is to have the expected value before the actual value.
>> We should all try make sure we get the arguments to assertEquals in the
>> correct order.  And fix any we spot that are the wrong way around. ;-)
>>
>> I've fixed a few of the more obviously incorrect method calls in
>> HARMONY-353.
>>
>> Regards,
>>  Mark.
>>
>> --
>> Mark Hindess <ma...@googlemail.com>
>> IBM Java Technology Centre, UK.
>>
>>     
>
>
> --
> Mark Hindess <ma...@googlemail.com>
> IBM Java Technology Centre, UK.
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>
>   


-- 
Richard Liang
China Software Development Lab, IBM 


Re: assertEquals in tests with incorrect argument order

Posted by Anton Avtamonov <an...@gmail.com>.
Completely agree about using proper 'asserts' :-).

Just want to remind about one more useful pair of methods -
assertSame()/assertNotSame() which are useful when comparing
instances. I saw many times in my practice that assertTrue(instance1
== instance2) was used intead. Besides, assertEquals() is also used
for that purpose sometimes which is definitely wrong...
Sometimes assertTrue(false) used instead of fail().

Actually, it is not too many 'assert' methods in
junit.framework.Assert class. May be it is a good idea for those who
never did it before to look at. Having all of them in mind will help
to use the most applicable when necessary.

--
Anton Avtamonov,
Intel Middleware Products Division


On 4/17/06, LvJimmy,Jing <fi...@gmail.com> wrote:
> 2006/4/17, Mark Hindess <ma...@googlemail.com>:
> >
> > Another type of test that could be improved are those using
> > assertTrue to compare two objects for equality.  Most of them should
> > be using assertEquals, assertNull or assertNotNull.
> >
> > Using assertEquals automatically gives more meaningful error messages.
> > It saves people writing asserts like:
> >
> >   assertTrue("Size should return 100, returned: " + map.size(),
> >              map.size() == 100);
> >
> > when this would do just as well:
> >
> >   assertEquals("Incorrect size", 100, map.size());
>
>
> Good idea. :)
>
> I'm going to submit a few (big) patches to fix some of these.
>
>
> I think there's a lot of them, even, few of our testcases is written in this
> style, so, good luck :)
> Anyway, we can discuss about this, and see if we can agree on some
> convention.
>
> Regards,
> > Mark.
> >
> > On 4/15/06, Mark Hindess <ma...@googlemail.com> wrote:
> > > Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
> > > quite confusing.  If you get the arguments to assertEquals the wrong
> > > way around you get errors like:
> > >
> > >   error expected <actual> but got <expected>
> > >
> > > rather than:
> > >
> > >   error expected <expected> but got <actual>
> > >
> > > The correct way around is to have the expected value before the actual
> > value.
> > > We should all try make sure we get the arguments to assertEquals in the
> > > correct order.  And fix any we spot that are the wrong way around. ;-)
> > >
> > > I've fixed a few of the more obviously incorrect method calls in
> > > HARMONY-353.
> > >
> > > Regards,
> > >  Mark.
> > >
> > > --
> > > Mark Hindess <ma...@googlemail.com>
> > > IBM Java Technology Centre, UK.
> > >
> >
> >
> > --
> > Mark Hindess <ma...@googlemail.com>
> > IBM Java Technology Centre, UK.
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
>
> --
>
> Best Regards!
>
> Jimmy, Jing Lv
> China Software Development Lab, IBM
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: assertEquals in tests with incorrect argument order

Posted by Geir Magnusson Jr <ge...@pobox.com>.
Yes, the > really helps.  I use Thunderbird too.  Amazingly, this 
setting can be found under "Account Settings", "Composition & 
Addressing".  Turn of HTML, and turn on Automatically quote....

Thanks

geir


Jimmy, Jing Lv wrote:
> Hi Geir:
>    Sorry for that, I'm trying Mozilla Thunderbird instead of Gmail on 
> firefox, perhaps I've mis-displaced something. It looks proper on my Gmail.
>    Try to fix it , shall I add a ">" ?
> 
>  >Geir Magnusson Jr wrote:
>> Can you fix your mailer so that it quotes properly?  Down below, you 
>> wrote "Good idea. :)" and Mark wrote "I'm going to submit...." and 
>> they have the same level of quoting... we can't follow the thread...
>>
>> thanks
>>
>> geir
>>
>> LvJimmy,Jing wrote:
>>> 2006/4/17, Mark Hindess <ma...@googlemail.com>:
>>>> Another type of test that could be improved are those using
>>>> assertTrue to compare two objects for equality.  Most of them should
>>>> be using assertEquals, assertNull or assertNotNull.
>>>>
>>>> Using assertEquals automatically gives more meaningful error messages.
>>>> It saves people writing asserts like:
>>>>
>>>>   assertTrue("Size should return 100, returned: " + map.size(),
>>>>              map.size() == 100);
>>>>
>>>> when this would do just as well:
>>>>
>>>>   assertEquals("Incorrect size", 100, map.size());
>>>
>>>
>>> Good idea. :)
>>>
>>> >I'm going to submit a few (big) patches to fix some of these.
>>>
>>>
>>> I think there's a lot of them, even, few of our testcases is written 
>>> in this
>>> style, so, good luck :)
>>> Anyway, we can discuss about this, and see if we can agree on some
>>> convention.
>>>
>>> Regards,
>>>> Mark.
>>>>
>>>> On 4/15/06, Mark Hindess <ma...@googlemail.com> wrote:
>>>>> Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
>>>>> quite confusing.  If you get the arguments to assertEquals the wrong
>>>>> way around you get errors like:
>>>>>
>>>>>   error expected <actual> but got <expected>
>>>>>
>>>>> rather than:
>>>>>
>>>>>   error expected <expected> but got <actual>
>>>>>
>>>>> The correct way around is to have the expected value before the actual
>>>> value.
>>>>> We should all try make sure we get the arguments to assertEquals in 
>>>>> the
>>>>> correct order.  And fix any we spot that are the wrong way around. ;-)
>>>>>
>>>>> I've fixed a few of the more obviously incorrect method calls in
>>>>> HARMONY-353.
>>>>>
>>>>> Regards,
>>>>>  Mark.
>>>>>
>>>>> -- 
>>>>> Mark Hindess <ma...@googlemail.com>
>>>>> IBM Java Technology Centre, UK.
>>>>>
>>>>
>>>> -- 
>>>> Mark Hindess <ma...@googlemail.com>
>>>> IBM Java Technology Centre, UK.
>>>>
>>>> ---------------------------------------------------------------------
>>>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>>>> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>>>> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>>>>
>>>>
>>>
>>>
>>> -- 
>>>
>>> Best Regards!
>>>
>>> Jimmy, Jing Lv
>>> China Software Development Lab, IBM
>>>
>>
>> ---------------------------------------------------------------------
>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>>
>>
> 
> 

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: assertEquals in tests with incorrect argument order

Posted by "Jimmy, Jing Lv" <fi...@gmail.com>.
Hi Geir:
    Sorry for that, I'm trying Mozilla Thunderbird instead of Gmail on 
firefox, perhaps I've mis-displaced something. It looks proper on my Gmail.
    Try to fix it , shall I add a ">" ?

 >Geir Magnusson Jr wrote:
> Can you fix your mailer so that it quotes properly?  Down below, you 
> wrote "Good idea. :)" and Mark wrote "I'm going to submit...." and 
> they have the same level of quoting... we can't follow the thread...
>
> thanks
>
> geir
>
> LvJimmy,Jing wrote:
>> 2006/4/17, Mark Hindess <ma...@googlemail.com>:
>>> Another type of test that could be improved are those using
>>> assertTrue to compare two objects for equality.  Most of them should
>>> be using assertEquals, assertNull or assertNotNull.
>>>
>>> Using assertEquals automatically gives more meaningful error messages.
>>> It saves people writing asserts like:
>>>
>>>   assertTrue("Size should return 100, returned: " + map.size(),
>>>              map.size() == 100);
>>>
>>> when this would do just as well:
>>>
>>>   assertEquals("Incorrect size", 100, map.size());
>>
>>
>> Good idea. :)
>>
>> >I'm going to submit a few (big) patches to fix some of these.
>>
>>
>> I think there's a lot of them, even, few of our testcases is written 
>> in this
>> style, so, good luck :)
>> Anyway, we can discuss about this, and see if we can agree on some
>> convention.
>>
>> Regards,
>>> Mark.
>>>
>>> On 4/15/06, Mark Hindess <ma...@googlemail.com> wrote:
>>>> Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
>>>> quite confusing.  If you get the arguments to assertEquals the wrong
>>>> way around you get errors like:
>>>>
>>>>   error expected <actual> but got <expected>
>>>>
>>>> rather than:
>>>>
>>>>   error expected <expected> but got <actual>
>>>>
>>>> The correct way around is to have the expected value before the actual
>>> value.
>>>> We should all try make sure we get the arguments to assertEquals in 
>>>> the
>>>> correct order.  And fix any we spot that are the wrong way around. ;-)
>>>>
>>>> I've fixed a few of the more obviously incorrect method calls in
>>>> HARMONY-353.
>>>>
>>>> Regards,
>>>>  Mark.
>>>>
>>>> -- 
>>>> Mark Hindess <ma...@googlemail.com>
>>>> IBM Java Technology Centre, UK.
>>>>
>>>
>>> -- 
>>> Mark Hindess <ma...@googlemail.com>
>>> IBM Java Technology Centre, UK.
>>>
>>> ---------------------------------------------------------------------
>>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>>> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>>> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>>>
>>>
>>
>>
>> -- 
>>
>> Best Regards!
>>
>> Jimmy, Jing Lv
>> China Software Development Lab, IBM
>>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 

Best Regards!

Jimmy, Jing Lv
China Software Development Lab, IBM


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: assertEquals in tests with incorrect argument order

Posted by Geir Magnusson Jr <ge...@pobox.com>.
Can you fix your mailer so that it quotes properly?  Down below, you 
wrote "Good idea. :)" and Mark wrote "I'm going to submit...." and they 
have the same level of quoting... we can't follow the thread...

thanks

geir

LvJimmy,Jing wrote:
> 2006/4/17, Mark Hindess <ma...@googlemail.com>:
>> Another type of test that could be improved are those using
>> assertTrue to compare two objects for equality.  Most of them should
>> be using assertEquals, assertNull or assertNotNull.
>>
>> Using assertEquals automatically gives more meaningful error messages.
>> It saves people writing asserts like:
>>
>>   assertTrue("Size should return 100, returned: " + map.size(),
>>              map.size() == 100);
>>
>> when this would do just as well:
>>
>>   assertEquals("Incorrect size", 100, map.size());
> 
> 
> Good idea. :)
> 
> I'm going to submit a few (big) patches to fix some of these.
> 
> 
> I think there's a lot of them, even, few of our testcases is written in this
> style, so, good luck :)
> Anyway, we can discuss about this, and see if we can agree on some
> convention.
> 
> Regards,
>> Mark.
>>
>> On 4/15/06, Mark Hindess <ma...@googlemail.com> wrote:
>>> Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
>>> quite confusing.  If you get the arguments to assertEquals the wrong
>>> way around you get errors like:
>>>
>>>   error expected <actual> but got <expected>
>>>
>>> rather than:
>>>
>>>   error expected <expected> but got <actual>
>>>
>>> The correct way around is to have the expected value before the actual
>> value.
>>> We should all try make sure we get the arguments to assertEquals in the
>>> correct order.  And fix any we spot that are the wrong way around. ;-)
>>>
>>> I've fixed a few of the more obviously incorrect method calls in
>>> HARMONY-353.
>>>
>>> Regards,
>>>  Mark.
>>>
>>> --
>>> Mark Hindess <ma...@googlemail.com>
>>> IBM Java Technology Centre, UK.
>>>
>>
>> --
>> Mark Hindess <ma...@googlemail.com>
>> IBM Java Technology Centre, UK.
>>
>> ---------------------------------------------------------------------
>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>>
>>
> 
> 
> --
> 
> Best Regards!
> 
> Jimmy, Jing Lv
> China Software Development Lab, IBM
> 

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: assertEquals in tests with incorrect argument order

Posted by LvJimmy,Jing <fi...@gmail.com>.
2006/4/17, Mark Hindess <ma...@googlemail.com>:
>
> Another type of test that could be improved are those using
> assertTrue to compare two objects for equality.  Most of them should
> be using assertEquals, assertNull or assertNotNull.
>
> Using assertEquals automatically gives more meaningful error messages.
> It saves people writing asserts like:
>
>   assertTrue("Size should return 100, returned: " + map.size(),
>              map.size() == 100);
>
> when this would do just as well:
>
>   assertEquals("Incorrect size", 100, map.size());


Good idea. :)

I'm going to submit a few (big) patches to fix some of these.


I think there's a lot of them, even, few of our testcases is written in this
style, so, good luck :)
Anyway, we can discuss about this, and see if we can agree on some
convention.

Regards,
> Mark.
>
> On 4/15/06, Mark Hindess <ma...@googlemail.com> wrote:
> > Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
> > quite confusing.  If you get the arguments to assertEquals the wrong
> > way around you get errors like:
> >
> >   error expected <actual> but got <expected>
> >
> > rather than:
> >
> >   error expected <expected> but got <actual>
> >
> > The correct way around is to have the expected value before the actual
> value.
> > We should all try make sure we get the arguments to assertEquals in the
> > correct order.  And fix any we spot that are the wrong way around. ;-)
> >
> > I've fixed a few of the more obviously incorrect method calls in
> > HARMONY-353.
> >
> > Regards,
> >  Mark.
> >
> > --
> > Mark Hindess <ma...@googlemail.com>
> > IBM Java Technology Centre, UK.
> >
>
>
> --
> Mark Hindess <ma...@googlemail.com>
> IBM Java Technology Centre, UK.
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


--

Best Regards!

Jimmy, Jing Lv
China Software Development Lab, IBM

Re: assertEquals in tests with incorrect argument order

Posted by Mark Hindess <ma...@googlemail.com>.
Another type of test that could be improved are those using
assertTrue to compare two objects for equality.  Most of them should
be using assertEquals, assertNull or assertNotNull.

Using assertEquals automatically gives more meaningful error messages.
It saves people writing asserts like:

  assertTrue("Size should return 100, returned: " + map.size(),
             map.size() == 100);

when this would do just as well:

  assertEquals("Incorrect size", 100, map.size());

I'm going to submit a few (big) patches to fix some of these.

Regards,
 Mark.

On 4/15/06, Mark Hindess <ma...@googlemail.com> wrote:
> Trying to fix/enable the PatternSyntaxExceptionTest (HARMONY-352) was
> quite confusing.  If you get the arguments to assertEquals the wrong
> way around you get errors like:
>
>   error expected <actual> but got <expected>
>
> rather than:
>
>   error expected <expected> but got <actual>
>
> The correct way around is to have the expected value before the actual value.
> We should all try make sure we get the arguments to assertEquals in the
> correct order.  And fix any we spot that are the wrong way around. ;-)
>
> I've fixed a few of the more obviously incorrect method calls in
> HARMONY-353.
>
> Regards,
>  Mark.
>
> --
> Mark Hindess <ma...@googlemail.com>
> IBM Java Technology Centre, UK.
>


--
Mark Hindess <ma...@googlemail.com>
IBM Java Technology Centre, UK.

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org