IntelliJ can't find classpath test resource

后端 未结 7 887
你的背包
你的背包 2020-12-02 14:18

I\'m having a problem where IntelliJ 13.1.4, when running a unit test, can\'t find a ServiceLoader file in the src/test/resources directory of my m

7条回答
  •  清歌不尽
    2020-12-02 14:35

    I managed to get it working better by creating a test-resources directory parallel to the test directory (!).

    Still seeing intermittent problems with this, though. Those times, it's possible to open the IntelliJ project settings and define the test resources as source instead (the Gradle project will remain unchanged).

    Must be an IntelliJ bug, as I've experienced the same thing in Android Studio.

    EDIT:

    I found a workaround to the issue.

    Add the following at the end of the Gradle config (and specify your test resources path):

    task copyTestResources(type: Copy) {
        from "${projectDir}/src/test/resources"
        into "${buildDir}/classes/test"
    }
    processTestResources.dependsOn copyTestResources
    

提交回复
热议问题