Using Clover with Maven + surefire-test + inner test classes

If you use Maven with the surefire-test plugin, its default filter setting for searching test classes is to skip inner classes:



In case when you have inner classes defined in your JUnit TestCases and you have configured a Surefire plugin to run your inner classes as well, you might get an error like this:

 Test set: TestUtils$__CLR2_6_34a4agh7gevmc
 Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.094 sec <<< FAILURE!
 initializationError(TestUtils$__CLR2_6_34a4agh7gevmc) Time elapsed: 0.016 sec <<< ERROR!
 java.lang.Exception: Test class should have exactly one public constructor
 at org.junit.runners.BlockJUnit4ClassRunner.validateOnlyOneConstructor(


This is because Clover generates inner class for each class (test or application code). In order to fix a problem, you have to change your pom.xml and filter out from your test scope any inner classes beginning with __CLR.

For example:

Last modified on May 21, 2012

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.