• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit Testing.

 
Mike Lonsky
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to do some JUnit testing for my Binary I/O. I've done some JUnit testing for getters & setters, but I have no idea where to start or what to do with this.
Help please? Thanks.

Here's my code:
https://gist.github.com/anonymous/9afadc3573c092119715
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
Gists are great for longer code. For something this short, it is ok to just post it inline.

The code in the gist is:


As far as how to test it, think about what it does. I see two paths through the code.

Exception case
If you pass null or a file that doesn't exist, you expect the error path to be executed. You could test that an exception isn't thrown to the caller. Or you could test that something is written to System.err if you want to be particularly thorough about it. (To do this, save System.err in an instance variable and change it to a stream you control.)

Happy path
The goal is to test a file is created with certain content. One way is to create a sample serializable object. Run it through your method. Then try to do the opposite - read in the file and see if you get the same object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic