Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble Reading from Properties File
    primarykey
    data
    text
    <p>I'm building a Java program that will automatically run a hundred or so tests. The program itself is in its final stages of production, and my boss wants me to take out all hard-coded variables and store them in a .properties file. Right now I have two java files Logic.java and Tests.java, and a properties files xxx.properties. However when I run the code (JUnit tests in Tests.java), it appears that the properties never get loaded. Relevant code follows:</p> <p>In Logic.java</p> <pre><code>Properties properties = new Properties(); String val1; String val2; ... String last_val; public void importProperties() { try { properties.load(new FileInputStream("xxx.properties")); val1 = properties.getProperty("val1-property-name"); ... lastVal = properties.getProperty("lastVal-property-name"); } catch (Exception e) { e.printStackTrace(); } } public void test() { importProperties(); //Testing code follows, several method calls referencing val1, val2, etc } </code></pre> <p>In Tests.java</p> <pre><code>Logic logic = new Logic(); @Before public void before() { logic.importProperties(); } @Test public void test1() { logic.testMethod(); } //More tests </code></pre> <p>}</p> <p>I should be importing the properties and setting the string vals in Logic.java in the @Before method since I'm not creating a new instance of Logic (or so I believe), but when I try to find the values of the strings (writing the string values to a log file), there's no text in said file. I know for a fact that the log file writing works, so the Strings aren't being set to their property values. My property file is also correctly written, I can provide more information if necessary. Thanks!</p> <p>Edit: So after a bunch of troubleshooting it looks as if the properties file is definitely being read since a properties.keys() call returns all the keys. It's not setting the strings the the key values, however. Still troubleshooting but any ideas would be helpful</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload