【问题标题】:app real path issue in spock integration test casespock集成测试用例中的应用程序真实路径问题
【发布时间】:2014-10-28 07:51:02
【问题描述】:

我正在处理使用jasper 生成pdf 的操作的集成测试用例。碧玉有一个sub-report。要获取子报告的路径(web-app/reports/ 中的abc.jasper),我首先使用获取真实路径

request.getSession().getServletContext().getRealPath("")

它给出/home/mkb/workspace/my-project/web-app,然后连接/reports/abc.jasper 以获取父jasper 报告中的子报告。这在运行应用程序 (run-app) 时工作​​正常。

但是在测试(test-app)上面的代码时给出/home/mkb/workspace/my-project/target/work/scriptCache,因此我得到了

net.sf.jasperreports.engine.JRException: Resource not found at : 
/home/mkb/workspace/my-project/target/work/scriptCache/reports/abc.jasper

如何在测试用例中设置或修复此路径问题?(Grails 2.3.9)

【问题讨论】:

    标签: grails testing integration-testing spock realpath


    【解决方案1】:

    请使用ServletContextHolder类静态方法getRealPath()获取真实路径。例如:-

    ServletContextHolder.servletContext.getRealPath('/')
    

    此代码将给出您的应用程序的 web-app 文件夹的路径。

    【讨论】:

    • 工作真棒。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 2017-04-10
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    相关资源
    最近更新 更多