How to test write to file in Java?

前端 未结 3 1238
花落未央
花落未央 2020-12-30 16:02

I\'m beginner, and keep yourself in hands. I have some easy program, and I need do junit test for write method. I have some collection in input. How I can do this? This my

3条回答
  •  [愿得一人]
    2020-12-30 16:42

    You seem to have the right idea so I am not sure what you need help with exactly...

    can we join both tests(write/read)

    yes.

    or better do this individually(coz if our test fall we don't know where is problem - in read or write)?

    Better but harder to maintain.

    How should make this correctly at junit(with prepare to test, and test itself)?

    Create some dummy data, in code or in a text file.

    In the first case, write out the file and read it back in as check it is the same.

    In the second case, you can read the text file and write it out again, and check it is the same.

提交回复
热议问题