Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails spock集成测试用例中的应用程序实际路径问题_Grails_Testing_Integration Testing_Spock_Realpath - Fatal编程技术网

Grails spock集成测试用例中的应用程序实际路径问题

Grails spock集成测试用例中的应用程序实际路径问题,grails,testing,integration-testing,spock,realpath,Grails,Testing,Integration Testing,Spock,Realpath,我正在使用jasper开发一个动作的集成测试用例,该动作生成pdf。jasper有一个子报告。要获取子报表的路径(webapp/reports/中的abc.jasper),我首先使用 request.getSession().getServletContext().getRealPath("") 它给出了/home/mkb/workspace/my project/web app,然后连接/reports/abc.jasper,以在父jasper报告中获得子报告。在运行应用程序(运行应用程序)

我正在使用
jasper
开发一个动作的集成测试用例,该动作生成
pdf
。jasper有一个
子报告
。要获取子报表的路径(
webapp/reports/
中的abc.jasper),我首先使用

request.getSession().getServletContext().getRealPath("")
它给出了
/home/mkb/workspace/my project/web app
,然后连接
/reports/abc.jasper
,以在父jasper报告中获得子报告。在运行应用程序(运行应用程序)时,此功能工作正常

但是在测试(测试应用程序)时,上面的代码给出了
/home/mkb/workspace/myproject/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)

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

ServletContextHolder.servletContext.getRealPath('/')

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

。谢谢