permaculture playing cards*
The moose likes Testing and the fly likes JUnit Testing. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit Testing." Watch "JUnit Testing." New topic
Author

JUnit Testing.

Mike Lonsky
Greenhorn

Joined: Feb 10, 2014
Posts: 3
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

Joined: May 26, 2003
Posts: 30764
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit Testing.