Use junit to test reading from text and binary files and writing to text and binary files?

When you're testing constructors you typically only need the following.

When you're testing constructors you typically only need the following: Ensure that the object created contains the values you expect (i.e. The values you passed in, or the data that results from some computation done on them) The data loaded into the objects matches those in the file (or another InputStream, if you don't want to use actual files in your tests) Exceptions are thrown for invalid input Other than that, there isn't much to do for constructors. In the case of your first constructor, which simply assigns values (without doing any disk I/O) I don't tend to test those constructors, because all you're really verifying is that the = operator in Java works, which we know is does.So, I would only write tests that cover the above situations for your second constructor.

– trs Sep 19 at 17:26 Depends on your situation, but when testing saving/loading, I typically test to make sure that (1) I can save without throwing errors, and (2) that I can load a file that was saved by my own code, and that the values loaded into the resulting Java object appear correct and valid. It doesn't have to be complex - you're just making sure that the round-trip from your application, to disk, and then back to your application retains your data in a form that is consistent from one run to the next.So when saving an integer value of '5', when I load it back from disk, it better still equal '5'. – normalocity Sep 19 at 17:34.

Fortunately, you haven't actually required files - so you can pass in a PrintWriter writing to a StringWriter, and a DataInputStream wrapping a ByteArrayInputStream etc, and test everything in memory. Another option is to have resources in your test project with expected output - always write to memory, but then check the expectations against those "golden" files, which you should probably load using Class. GetResource rather than a FileInputStream (to avoid having any file system dependency).

Can you elaborate I am new to this – trs Sep 19 at 15:01 @trs: I've added a bit more information, but it would help if you'd say which bit you're having problems with. – Jon Skeet Sep 19 at 15:02.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions