I’ve recently started creating my own annotations and to sport TDD/BDD, I’d want to unit test my annotations to create a clear specification for them. However since annotations are basically merely fancy interfaces which to my knowledge can’t be really instantiated directly, is there any way short of reflection to unit test an annotation?
I’ve recently started creating my own annotations and to sport TDD/BDD, I’d want to
Share
It’s not something I would usually write tests for, but you could simply create a set of test classes which use and abuse the annotation, to test that it is storing its member values, that it has the correct defaults etc.
This will only work on Runtime annotations that are specfied on the correct targets of course.
In my experience, annotations themselves are rarely interesting enough to warrant unit tests – it is usually the code which uses them that needs testing. But then I’m not from the 100% code coverage school of thought 🙂