1
我有從JUnit測試中的XML負載性能問題(在相同的代碼工作良好,沒有JUnit的):Properties.loadFromXML NullPointerException異常使用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);
...
,如果我跑的測試,我得到
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)
不幸的是,我找不到使用這個堆棧跟蹤的問題。首先,我認爲文件沒有找到(它位於/ src/test/resources)。但是 System.out.println(loader.getResource(「analyse.properties.xml」)); 返回正確的文件路徑。
誰能幫助嗎?
我用STS 2.9.1與Maven(插件版本2.3.1,因爲我認爲)和Ubuntu下的12.04 AMD64的JUnit 4.10。
謝謝你在前進, 親切的問候。
謝謝。我非常愚蠢的錯誤。 – 2012-07-07 11:30:31