【发布时间】:2013-12-22 15:30:15
【问题描述】:
我通过 Eclipse 中的 JVM 参数在系统变量中设置了一个文件夹路径,我试图在我的类中访问它:
System.getProperty("my_files_path")。
在为此类编写 junit 测试方法时,我尝试模拟此调用,因为测试类不考虑 JVM 参数。我使用 PowerMockito 模拟静态 System 类,并尝试在调用 System.getProperpty 时返回一些路径。
在类级别有 @RunWith(PowerMockRunner.class) 和 @PrepareForTest(System.class) 注释。但是, System 类没有被嘲笑,因此我总是得到空结果。
任何帮助表示赞赏。
【问题讨论】:
标签: java mocking environment-variables system powermock