【问题标题】:Where to place properties files when running tests via maven + grizzly + jersey test framework?通过 maven + grizzly + jersey 测试框架运行测试时在哪里放置属性文件?
【发布时间】:2013-06-06 00:31:56
【问题描述】:

当我尝试运行我的JerseyTest 时,来自我的源 (src/main/resources) 文件夹 keepa 的 my.properties 文件被拾取并使用......而我想要测试文件夹中的属性文件 (src/test/resources ) 来使用。

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
    myProperties.load(classLoader.getResourceAsStream("my.properties"));
}

如何在 Maven 中进行配置?

我正在使用:

  1. maven-compiler-plugin 版本2.1
  2. jersey-test-framework-grizzly2 版本1.13

更新(根据接受的答案解决):

我注意到文字skip non existing resourceDirectory

[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ xxx ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /xxx/xxx/xxx/xxx/src/test/resources

原来我拼错了资源,修复它后,一切都按照接受的答案中的描述工作。

当我浪费时间寻找解决方法时,我确实找到了一些有趣的链接,用于基于配置文件配置属性文件:

  1. How can I change a .properties file in maven depending on my profile?
  2. http://maven.apache.org/guides/mini/guide-building-for-different-environments.html

【问题讨论】:

    标签: maven junit jersey grizzly


    【解决方案1】:

    当从src/test/java 文件夹运行某些东西时,默认行为是:

    • 它将提取src/main/resources中的文件;
    • 除非src/test/resources中有同名文件。

    所以基本上它会用src/test/resources的内容“覆盖”src/main/resources的内容:

    • 如果您在两个文件夹中都有文件,则以src/test/resources 中的文件为准。
    • 如果您仅在src/main/resources 中获得了一个文件,它将被使用。
    • 如果您仅在src/test/resources 中获得了一个文件,它将被使用。

    【讨论】:

    • 我明白你在说什么,但即使src/test/resources 中有同名字段,它也会选择src/main/resources 中的那个...还有其他建议吗?
    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2022-08-02
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多