I am developing a spring + maven project. And in some classes I am reading XML file in my project. Path for the XML is on properties file. But it will take the path from the Catalina base. Its working fine. But when I need to execute the test case, I can not get the correct path because it will depend on Catalina base.So how can I access my XML file when Junit running?
My properties file
projecthieararchy.read.derectory=/webapps/phdash/WEB-INF/config/Programs.xml
XML is reading from various .java files So I need to get the class path combination to the properties file.
ie. Test files located like this
1. Framework --> src --> test --> delegate--> Test1.java
2. Framework --> src --> test --> delegate--> somefolder ---> Test2.java
I can a add copy of XML to test like, XML can be located
Framework --> resources ---> Programs.xml
How to add the test file path in property file??
Thanks.
My suggestion is to tell the junit runner where the base directory of the XML files is. You can configure the "work directory" for junit runner to be Catalina base:
If you're running junit tests in command line. you can do it as this:
$cd /path/to/Catalina/base
$ (invoke junit runner)
You could create a test-specific properties file in src/test/resources
that would contain the projecthieararchy.read.derectory
with a value appropriate for the tests. eg
projecthieararchy.read.derectory=path/used/by/tests/to/Programs.xml
That would override the real value in the production properties - when running the tests.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.