代码之家  ›  专栏  ›  技术社区  ›  Arthur Ronald

如何设置maven在运行测试时覆盖另一个设置文件?

  •  5
  • Arthur Ronald  · 技术社区  · 16 年前

    请参阅以下Maven生成的项目

    target
        classes
        test-classes
    src
        main
            java
            scripts
            resources
                datasource-settings.xml
        test
            java
            resources
                datasource-settings.xml
    

    我想, 运行测试时 ,以使用在test/resources/datasource-settings.xml中找到的设置,而不是main/resources/datasource-settings.xml。有可能吗?如果是这样,我该怎么做才能达到目标?

    2 回复  |  直到 16 年前
        1
  •  9
  •   Pascal Thivent    16 年前

    放置的资源 ${basedir}/src/test/resources (默认位置)将自动添加到maven为单元测试设置的类路径中,并优先于 ${basedir}/src/main/resources . 所以你想要做的实际上只是默认的行为。

        2
  •  3
  •   Jeff Storey    16 年前

    如果您没有修改POM中的资源设置,那么测试资源应该首先显示在类路径中,因此测试应该在主文件之前找到该文件,而不需要做任何额外的工作。你看到了什么样的行为?