Skip to content

Contributors' corner : testing

stephanenicolas edited this page Sep 17, 2013 · 3 revisions

Testing is a primary matter in the design of the BoundBox library itself.

There are 3 batch of tests in BoundBox :

  • Unit tests of the BoundBoxProcessor. They ensure the processor can process an annotated class and produce the right meta-data (see org.boundbox.model classes) for the bound class.
  • Unit tests of the BoundBoxWriter. They ensure the writer can process the meta-data of a bound class (e.g. Foo) and create a BoundBox class (e.g. BoundBoxOfFoo) that compiles and contains the expected methods for a BoundBox.
  • Integration testing (in a different maven module). They ensure that, given a class Foo and its BoundBoxOfFoo class, all field accesses and method invocations on a BoundBoxOfFoo object will actually trigger the right field access and method invocation in the underlying bound instance of Foo itself.

All new features of BoundBox should be tested that way.


Unit tests are quite advanced in BoundBox. As testing an annotation processor is not that common and easy, here are some details :

Here is the folder structure of the library :

  • src/main/java : library's code
  • src/test/java : library's unit tests code
  • src/main/resources : a set of java files that will be used during tests.

When unit testing the boundbox annotation processor, the resource java files will be annotation processed using the processor. This is achieved through a compilation cycle of the resource files. For one of those files to compile, you may need to add some others to the classpath. The BoundBoxProcessorTest contains some helper methods to do it. In the same way, some helper methods will help to test the meta data produced by the annotation processor.

When unit testing the boundbox writer, the resource java files, we inject some given meta data into the writer to see how it can produce a BoundBox class. Once the BoundBox java file is produced, we compile it using a java compiller. This compilation step will require other classes (typically the bound class, it's super class and imported classes). Here again, we use the resources java files but this time to compile the BoundBox class itself. The BoundBoxWriterTest contains some helper methods to do it. After compilation, we can use reflection on the compiled BoundBox class to test that it contains desired methods.


Integration tests reside in a separate project located at project's root. They are quite standard and don't require further explanations.