I have following directories structure:
UPDATED STRUCTURE
src
|
-test
|
-java
| |
| -SomeXmlTest.java
|
-resources
|
-someXmlContent.xml
I think something like that bad practise:
new File(C:\Project ... \src\resources\someXmlContent.xml)
// or magic dance like that
File currentDir = new File(System.getProperty("user.dir");
File parent = currentDir.getParent();
for (File file:parent.listFiles()){
//find resources directory and iterate over it files
}
I believe that there is simple annotation base solution, for example I just write “src\resources\someXmlContent.xml” in some annotation and testng resolve path automatically, but how can I do this?
Use resources instead of files. In this way you can pack your application in a jar and retrieve the resource inside of the jar.
Use an InputStream instead of a File/FileInputStream:
That is a more generic solution than File.