How should I discover test-resource files in a Maven-managed Java project?

后端 未结 4 1150
北恋
北恋 2021-02-13 21:06

I have a project that uses the normal Maven structure, e.g.

module
\\ src
  \\ main
    - java
    - resources
  \\ test
    - java
    - resources
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-13 21:50

    Try this?

    1)put test data files into the same package structure as you test classes. That is, if you have a test class named Apple in src/test/java/com/fruits, you test data file will be in src/resources/java/com/fruits.

    2) When the files are compiled both the class and the data file should be in target/test-classes/com/fruits. If this is the case, in you code, you can obtain the file this way "this.getClass().getResourceAsStream("myFile")"

提交回复
热议问题