[英]Issue with JUnit and Class Loaders
I'm working on a Maven project in IntelliJ whose tree looks like: 我正在IntelliJ中的Maven项目中,其树如下所示:
-resources (marked as default resource folder)
-src
Inside src there are 在src里面有
-src/main
-src/test
While inside resources there's a file called "windows.json" that i need to parse. 在资源内部,我需要解析一个名为“ windows.json”的文件。
As of now, the class that needs to parse the json is src/main/java/utils/WindowBuilder.Java
and I'm using an InputStreamReader
by passing to its constructor: 到目前为止,需要解析json的类是
src/main/java/utils/WindowBuilder.Java
,我通过将InputStreamReader
传递给其构造函数来使用它:
ClassLoader.getSystemClassLoader().getResourceAsStream("windows.json");
The code works just fine on its own, but if I try to run tests from src/test
using WindowBuilder
class I get a NullPointerException
when trying to retrieve the resource. 该代码本身就可以正常工作,但是如果我尝试使用
WindowBuilder
类从src/test
运行测试,则在尝试检索资源时会收到NullPointerException
。
What am I doing wrong? 我究竟做错了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.