views:

244

answers:

2

Hi There!

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.

A: 

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...

serg10
+2  A: 

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

Synox