2

I use nested classes for accessing private members in JUnit tests. They are alaways named "TestProxy".

I would like to remove them at Build time using maven2, to not include it into the jar file.

  • Is there any configuration option?
  • Can it be done with a plugin? If so, a prototype would be nice! ;-)

Thanks

Edit: Why use private methods? I need to inject data from 3rd party systems, that just can't be called for every JUnit test run. And i really don't want a public setter for private data, or sooner or later another programmer may misuse it.

4
  • Shouldn't classes in the tests folder already NOT be included in the JAR, by default?
    – matt b
    Apr 14, 2009 at 13:33
  • I am Talking about nested classes. A class withing an other class. Those classes are in normal source tree, compiled e.g. as "MyTestClass$TestProxy.class"
    – Synox
    Apr 14, 2009 at 14:19
  • So it's a part of the src folder, but you don't want it in the final packaged output? I don't really understand why you would include it in the src folder then...
    – matt b
    Apr 14, 2009 at 15:50
  • 1
    I mean, sounds like your workarounds to enable easier unit testing of certain components are requiring even further workarounds... which should tip you off that maybe the original workarounds aren't the best idea
    – matt b
    Apr 14, 2009 at 15:51

2 Answers 2

2

Here is the answer: It can be configured with maven. Just insert the following code into the file pom.xml in the build/plugins section:

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-jar-plugin</artifactId>
 <configuration>
   <excludes>
     <exclude>**/*$TestProxy*</exclude>
   </excludes>
 </configuration>
</plugin>

@see the Documentation: http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#excludes

0

For this sort of thing you might find that an ant script is the first port of call rather than a dedicated custom plugin. It is simple to get Maven to run arbitrary ant scripts as part of the build. Simpler than creating a plugin. This question has an excellent description of how to run an ant script with Maven's process-sources build execution phase.

On a slightly different note, I expect you will get a bunch of answers asking you why you are unit testing privately accessible class members...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.