Hi,

looking at some metamodel test code today I found a test method 'doTest' w/ 200 
lines of code and countless assertions
of the form 'assertTrue/False(condition)', 'assertEquals(expected, actual)'.

I am having several problems with this type of testing:

* test method should be descriptive, for example 
testForeignKeyBindingManyToOne, testBagBinding, testSetBinding, …
* test method should be short and in a perfect case one make a couple of 
assertions per test (then you often don't even
  need much comments, because the test name directly hints to what you are 
testing). Rather repeat some setup code 
  in each method than asserting EVERYTHING there is to a EntityBinding (as 
example)
* Avoid assertTrue/False. assertEquals has a much more helpful message if 
things fail. If you use assertTrue/False add 
  a message about your expectation
* Add assertion messages (also for assertEquals)

Why do I care? Once the code breaks you need at a first step understand what 
actually gets tested and that is easier with
short descriptive methods and assertion messages.

--Hardy


_______________________________________________
hibernate-dev mailing list
hibernate-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev

Reply via email to