How to unit test a method that reads a given file

前端 未结 4 1054
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 23:55

I know this is a bit naive. How to unit test this piece of code without giving physical file as input. I am new to mockito and unit testing. So I am not sure. Please help.

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 00:30

    Why do you wanna mock a file? Mocking java.io.File is a bad idea as it has loads of native stuff. I would advice you to ensure that a minimalist text file is available in classpath when the unit tests are run. You can convert this file to text and confirm the output.

提交回复
热议问题