Reflection in unit tests for checking code coverage

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-05-20T13:47:53Z Indexed on 2010/05/20 13:50 UTC
Read the original article Hit count: 255

Filed under:
|
|
|
|

Here's the scenario. I have VO (Value Objects) or DTO objects that are just containers for data. When I take those and split them apart for saving into a DB that (for lots of reasons) doesn't map to the VO's elegantly, I want to test to see if each field is successfully being created in the database and successfully read back in to rebuild the VO.

Is there a way I can test that my tests cover every field in the VO? I had an idea about using reflection to iterate through the fields of the VO's as part of the solution, but maybe you guys have solved the problem before?

I want this test to fail when I add fields in the VO, and don't remember to add checks for it in my tests.

© Stack Overflow or respective owner

Related posts about testing

Related posts about junit