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文件夹的路径。。谢谢