Maven 单元测试 FileNotFound 错误
我创建了一个 Maven 项目,其中涉及在完成时“写出”一个 CSV 文件。
我创建了一个测试类来生成“模拟/测试”报告文件,但是在运行单元测试时,使用“mvn package”或“mvn test”命令时,我收到此错误:
28 Jan 2012 11:17:51,499 main DEBUG main.executors.ReportsExecutor:111 - Finished processing documents in 0.0 hours
28 Jan 2012 11:17:51,516 main ERROR main.utilities.FileWriterObject:279 - writeToADelimitedFile: reports/reportResults_1_28_2012_11.17.515.csv (No such file or directory) APPEND VALUE: false
28 Jan 2012 11:17:51,517 main ERROR main.executors.ReportsExecutor:170 - java.io.FileNotFoundException: reports/reportResults_1_28_2012_11.17.515.csv (No such file or directory)
java.io.FileNotFoundException: reports/reportResults_1_28_2012_11.17.515.csv (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at java.io.FileWriter.<init>(FileWriter.java:61)
at
请记住“APPEND VALUE” : false”输出只是一个调试语句,让我知道 FileWriter 构造函数中的“append”布尔参数为 false,以便使用相应的文件名“创建”一个新文件。
现在,在生产中,它运行得很好。只是我的单元测试不起作用。是否有一些我没有配置的“根测试”目录?
我对 Maven 还很陌生。非常感谢任何反馈!
I created a Maven project that involves "writing out" a CSV file on completion.
I created a test class to generate a "mock/test" report file, but when running my unit test, when using the "mvn package" or "mvn test" commands, I get this error:
28 Jan 2012 11:17:51,499 main DEBUG main.executors.ReportsExecutor:111 - Finished processing documents in 0.0 hours
28 Jan 2012 11:17:51,516 main ERROR main.utilities.FileWriterObject:279 - writeToADelimitedFile: reports/reportResults_1_28_2012_11.17.515.csv (No such file or directory) APPEND VALUE: false
28 Jan 2012 11:17:51,517 main ERROR main.executors.ReportsExecutor:170 - java.io.FileNotFoundException: reports/reportResults_1_28_2012_11.17.515.csv (No such file or directory)
java.io.FileNotFoundException: reports/reportResults_1_28_2012_11.17.515.csv (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at java.io.FileWriter.<init>(FileWriter.java:61)
at
Keep in mind that the "APPEND VALUE: false" output is just a debug statement letting me know that the "append" boolean parameter in the FileWriter constructor is false, in order to "create" a new file with the respective file name.
Now, in production, it works just fine. It's just my unit tests that aren't working. Is there some "root test" directory that I'm not configuring?
I'm quite green to Maven. Any feedback is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Maven 设置了一个名为“basedir”的属性,可以方便地在单元测试中使用。我编写了一个快速单元测试,这在 Maven 和 Eclipse 中都适用:
当使用 System.getProperty(...) 获取“basedir”系统属性时,请务必将默认参数设置为“。”这样您也可以在 Eclipse 中运行单元测试:
Maven sets a property called "basedir" which is convenient to use in unit tests. I wrote a quick unit test and this works for me in both maven and in Eclipse:
When using System.getProperty(...) to get the "basedir" system property be sure to set the default parameter to "." so that you can run the unit test in Eclipse as well: