I have the problem with loading properties from xml inside jUnit test (the same code works well without jUnit):
public class InternetMapTest {
private Properties properties;
@Before
public void readProperties() {
try {
ClassLoader loader = ClassLoader.getSystemClassLoader();
InputStream stream = loader.getResourceAsStream("analyse.properties.xml");
properties.loadFromXML(stream);
…
if I run test, I get
java.lang.NullPointerException
at xxx.yyy.zzz.analyse.tests.InternetMapTest.readProperties(InternetMapTest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
...
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Unfortunately, I can’t identify the problem using this stack trace. First of all, I thought that the file was not found (it’s located in /src/test/resources). But
System.out.println(loader.getResource(“analyse.properties.xml”));
returns correct file path.
Can somebody help, please?
I use STS 2.9.1 with Maven (plugin version 2.3.1, as I think) and jUnit 4.10 under Ubuntu 12.04 amd64.
Thank you in advance,
Kind Regards.
Variable “properties” may be null, you would have to create it before calling the loading function.