Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-apt-dev] unit test for annotation processors?


Hi,

Does anyone have any suggestions for unit testing annotation processors? At a high level, an ideal situation would be if there was a factory method for AnnotationProcessorEnvironment objects which took a Java source file as input (perhaps as a String containing source code, or more conveniently a reference to a file). The APE instance could then be passed into the constructor of the annotation processor and the process method called. The behaviour could then be measured by obtaining the Messager instance from the APE and interrogating it for the expected set of errors.

I couldn't see an obvious factory method of that sort, so I tried a few ideas using Proxies, reflection, subclasses etc. Unfortunately, the design of BaseProcessorEnv seems to make this quite difficult. The constructor calls AptPlugin.getAptProject(javaProj); which makes it difficult to create an instance to delegate calls to without having a valid IJavaProject.

Anybody been down this road already and have some pointers?

Thanks,

James Kingdon

Back to the top