【问题标题】:Handle different source folder in Eclipse在 Eclipse 中处理不同的源文件夹
【发布时间】:2019-07-01 11:50:58
【问题描述】:

我正在进行的项目有常规的 src/main 和 src/test 文件夹,但他们最近引入了 src/integration-test,顾名思义,它应该包含集成测试。

不幸的是,我似乎无法使用 Maven 和 Eclipse 进行这项工作。我尝试添加一个源文件夹,但 Eclipse 无法解析集成测试所需的依赖项,并且无法编译测试类。我也无法使用 JUnit 开始测试。

源文件夹已添加到构建路径,但没有帮助。

我团队中的所有其他开发人员都使用 IntelliJ,并报告说他们根本没有这些问题。但它也一定能与 Eclipse 一起工作,对吧?

【问题讨论】:

  • 当您将文件夹添加为源文件夹类型时,应该在 Eclipse 中工作。
  • 我试过了,但 Eclipse 无法解析测试导入。
  • 通常,您不这样做,而是将 both 单元测试和集成测试放入 test 文件夹。然后通过命名约定将它们分开。

标签: java eclipse maven testing integration-testing


【解决方案1】:

您应该通过将源文件夹添加到构建中来使用 maven 处理此问题:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/integration</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

在此示例中,构建将添加一个 src/integration 文件夹,您可以在其中放置其他测试类。

有关更多信息,请查看build helper plugin 文档。

【讨论】:

  • 谢谢!做到了。
猜你喜欢
  • 2011-04-13
  • 2015-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-03
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
相关资源
最近更新 更多