Automatic, non-invasive addition of class invariants for unit testing


More info


CheckInv is an Eclipse plugin that automatically and non-invasively adds class invariant checks to a Java package. The checks are stored separately in a JSON file.

screenshot of a JUnit test failing because a class invariant didn't hold

Other approaches to this tend to use either a precompiler, a replacement compiler, or Java's reflection capability, but our goal was to find a design pattern that would add the checks in a language agnostic way.

(Even then, there is prior art, especially that of Brian A. Malloy at Clemson University. For more information, see #19, #26, and #40 here. Our work differs by attempting to support abstract and generic classes, as well as checks involving fields that don't already have accessor methods.)

Although this plugin is largely a proof-of-concept tool in support of the design pattern, it's quite functional as-is. The generated classes can be used as drop-in replacements in unit testing, and if an invariant should fail to hold, the tester is told which one failed, during which method call, and during which test. That makes debugging much easier, as we discovered when it found some bugs of our own!

Please visit for more information, or grab the current source at:

This design is based on Dave Reeder's Grapes at The pomegranate isn't a logo (it isn't licensed for that). It'd make a good software object, though—the outside is rough and the insides are weird and leaky.