Java – unit test for parsing files. How to load files from within the application?

I want to test a service method for parsing Excel files

>I want to create a test folder for Excel files under web app. What should I do? > How do I load files in a unit test?

Please give me some advice. Thank you

Solution

I usually put the file into the resource and load it as this getClass(). getResourceAsStream(“my.xsl”).

Please note that. If you put the file in the same package as the test, just enter the local name Otherwise, you should provide an absolute path starting with / If your application does not know how to use streams and needs files, use this getClass(). getResource(“my.xsl”). getFile().

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>