Saturday, 15 June 2013

java - Change property file located in src/test/resources -


I am looking for Apache common configuration and want to do a test which only / from XML file / / Trial / resource So far, I'm not having any problem, but I can not write anything in this file. If I change the location of the file in the file system / test / processing in second place (example: C: / test), then everything works fine, can you please help me about this?

Edit

Even I have tried so far:

  @Test Public Zero Test () Forward Configuration Expression { // Data is located in the first XML src / test / resources XMLConfiguration config = new XMLConfiguration ("data.xml"); & Lt; Object & gt; Line = config.getList ("user.username"); Println (rows); // This config.setProperty ("user.username", "FromTest") is not working; Config.save (); // Second XMLConfiguration with different x.xml config data = new XMLConfiguration ("c: /temp/data.xml"); & Lt; Object & gt; Line = config.getList ("user.username"); Println (rows); // This works config.setProperty ("user.username", "FromTest"); Config.save (); }  

Thanks.

Well, you do not provide much information about the current context, but src / Test / resources From the path, I think that if you work with Maven, if this is true, then it happens:

  1. Maven test / resources Classes
  2. Resources have been copied, the test method is running on the copy resource, thus target / test-classes / data.xml

If you check this file, Programmed it works I just saw the source file, went unread actually your code file.

The difference in the second exam, c: /temp/data.xml , is that the former is a relative path, while the latter is complete, and not within the scope of Maven.


No comments:

Post a Comment