Alex Rivera | Logout

How can I compare files in a JUnit test case?

Asked 2010-09-15T08:06:54.227
22

I want to implement JUnit on a small project I'm working on because I want to learn a little bit about it.

The tutorials that I read all make reference to methods that have a particular output.

In my case my output are files, how can I do this? any simple example? any approach that could help me with this?

The files are raw text files that are build by a void private method.

Edit
Report

1 Answer

1

Although your question may seem simplistic it does strike to the heart of unit testing, one needs to write well formed code that is testable. This is why some experts advise that one should write the unit test first and then the implementing class.

In your case I suggest you allow your method to execute and create the file(s) expected, following which your unit test(s) can analyse that the files are formed correctly.

answered 2010-09-15T08:14:35.503

Your Answer