我使用嵌套类来访问 JUnit 测试中的私有成员。 它们总是被命名为“TestProxy”。
我想在构建时使用 maven2 删除它们,不将其包含到 jar 文件中。
- 有什么配置选项吗?
- 可以用插件来完成吗? 如果是这样的话,原型就很好了! ;-)
谢谢
编辑:为什么使用私有方法? 我需要从第 3 方系统注入数据,但无法为每个 JUnit 测试运行调用这些数据。 我真的不想要私有数据的公共设置器,否则迟早另一个程序员可能会滥用它。
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.
发布评论
评论(2)
答案是这样的:可以用maven来配置。 只需将以下代码插入到文件 pom.xml 的 build/plugins 部分:
@see the Documentation: http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#excludes
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:
@see the Documentation: http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#excludes
对于此类事情,您可能会发现 ant 脚本是第一个调用端口,而不是专用的自定义插件。 让 Maven 在构建过程中运行任意 ant 脚本很简单。 比创建插件更简单。 这个问题很好地描述了如何使用 Maven 的
process-sources
构建执行阶段运行 ant 脚本。稍微不同的是,我希望您会得到一堆答案,询问您为什么要对可私有访问的类成员进行单元测试......
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...