如何将另一个测试源文件夹添加到Maven并将其编译到单独的文件夹? [英] Howto add another test source folder to Maven and compile it to a separate folder?

查看:221
本文介绍了如何将另一个测试源文件夹添加到Maven并将其编译到单独的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的单元测试有默认的 src / test / java 文件夹。单独的文件夹 src / integration / java 可用于集成测试。

I have the default src/test/java folder for our unit tests. A separate folder src/integration/java is available for the integration tests.

我配置了 maven-surefire-plugin 在各自的阶段执行单元/集成测试。当编译的类位于正确的目录中时,这非常有用。不幸的是,Maven只支持一个测试源文件夹和一个测试输出文件夹。

I configured the maven-surefire-plugin to execute the unit/integration tests in their respective phases. This works great when the compiled classes are in the correct directory. Unfortunately Maven only supports one test source folder and one test output folder.

使用mavens build-helper插件我可以添加另一个测试源文件夹,但编译的类将生成进入测试类但我想将类从 src / integration / java 编译成目标/集成测试的类。这可能吗?

With mavens build-helper plugin I could add another test-source folder but the compiled classes will be generated into test-classes but I want to compile the classes from src/integration/java into target/integration-test-classes. Is this possible?

src/test/java > target/test-classes
src/integration/java > target/integration-test-classes

PS:我不喜欢这个排除/包含在包基础上解决方案(从默认测试阶段排除所有 ** / it / ** 文件,并排除所有 ** / unit / ** 来自整合阶段。

PS: I don't like this exclude/include on package base solution (exclude all **/it/** files from the default test phase, and exclude all **/unit/** from the integration phase.

推荐答案

对不起,没有办法做到这一点,恕我直言,即使有一些黑客入侵这个概念是编译类只有一个目标目录,而编译测试类只有一个目标目录(甚至< build> 标签模式暴露了这个)。说实话,我不喜欢我真的认为应该可以使用Maven。通过使用精心设计的模块,Maven可以提升应用程序的直观,干净和清晰的设计。

Sorry, there's no way of doing that, IMHO even with some hacking in mind. The concept is that there's only one target directory for compiled classes and one for compiled test classes (even <build> tag schema exposes this). To be honest, I don't really think it should be possible with Maven. Maven promotes straight, clean and legible design of your application, by using well-crafted modules.

如果你真的想想你的话我们要做的是实际创建集成测试模块。事实上,这是常见的做法。到目前为止,我总是有单独的集成测试模块,从来没有遇到过这方面的问题。你当然应该依赖o n所有需要的模块来运行这些测试。您甚至可以依赖于其他模块的测试类,使用< type> test-jar< / type> 以及您在此处提到的依赖声明:

If think what you really want to do is to actually create integration tests module. That's the common practice, in fact. So far I always had separate integration testing module and never had problems with that. You should of course depend on all needed modules to run these tests. You can even depend on other module's test classes by using <type>test-jar</type> with your dependency declaration as mentioned here:

http://maven.apache.org /guides/mini/guide-attached-tests.html

我不喜欢这种方法,并且通常更喜欢单独的模块与测试支持东西,比如JUnit测试用例的基类等。

I don't like this method, however, and usually prefer to have separate module with testing support stuff, like base classes for JUnit test cases etc.

这篇关于如何将另一个测试源文件夹添加到Maven并将其编译到单独的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆