One of this situations is how to test a equals method and ensure that all the attributes are tested correctly. Most of the time we just test if all the fields are equals or not.
It is ok, but it is far from being complete and usefull.
Here is a pattern that you can follow and it will insure that all the fields are being tested correctly:
- Create two values for each of your class attribute, with different values between them;
- Create two objects, instances of the class that you want to test, call one as base and the other as ref;
- Make this block of code for each attribute (it doesn't matter the sequence):
base.setAttribute(ATTRIBUTE); |
Making things like this will insure that your test code for equals works perfect. Let's say that it is a little bit painful to make it for a big class, but of course you could automate it.
2 comentários:
painful, my friend, painful... lol
Speaking seriously, it is common for us to misspell words on a language that, well, we don´t speak everyday, so I recommend the spelling check tool from Firefox. ;)
Cheers!
Sorry my friend, I just corrected my terrible mistake ;)
Postar um comentário