vb.net - unit test equality covers all properties -


i have .net class in implemented gethashcode , equals.

while believe covered properties , have tests these functions, there case in future adds property , forgets add gethashcode , equals functions. forgetting these function result in equals function returning true objects differ new property.

i looking tool or code can use in testing code, loop through existing properties of object , test if forgotten.

the unit test this:

for each property in targettype     dim instance1 new targettype     dim instance2 new targettype     instance1.property=1     instance2.property=2     assert.arenotequal(instance1,instance2) next 

of course property assignment should smart use correct data type

if concerned new properties being added class, suggest serializing objects first , comparing resulting strings.

this ensure properties considered comparison in application , in unit tests.

the serializing helper method below (i referred this thread)

'meant extension method public shared function serializeobject(of t)(byval input t) string         dim xmlserializer = new xmlserializer(input.gettype())         dim textwriter = new stringwriter()         xmlserializer.serialize(textwriter, input)         return textwriter.tostring() end function 

you use above method in custom equals method. hope helps.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -