【问题标题】:Gradle - running a junit test not finding my xml fileGradle - 运行junit测试没有找到我的xml文件
【发布时间】:2014-03-06 16:29:10
【问题描述】:

我有一个简单的 junit 测试任务。

task testSanity(type: Test, dependsOn: testClasses) {
    def springInstrumentJarPath = project.configurations.compile.find { it.name.startsWith("spring- instrument") }    
    jvmArgs '-javaagent:' + springInstrumentJarPath  
    exclude '**/*TimeBaseTest*'
    exclude '**/*SuiteTests*'
}

问题是我在以下位置为我的 ehcache 添加了一个新的 xml 文件:

/src/main/webapp/WEB-INF/classes/ehcache.xml

我的所有测试都失败了,因为 junit 无法找到该文件。 如何在 gradle 任务中定义这个?

谢谢。

【问题讨论】:

  • 由 p:configLocation="classpath:/ehcache/ehcache.xml" 修复并将 ehcache 放在 src/main/resources/ehcache/ehcache.xml 中

标签: java spring junit build gradle


【解决方案1】:

src/main/webapp 应该只包含不从 Java 代码中使用的文件(更准确地说,是不由类加载器加载的文件)。 Java 资源应该转入src/main/resources。因此,将文件移动到src/main/resources/ehcache.xml 应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 2014-04-23
    • 2018-08-19
    • 2018-08-22
    • 2021-12-16
    • 1970-01-01
    相关资源
    最近更新 更多