File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Not sure how to go about these tests, JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Not sure how to go about these tests, JUnit" Watch "Not sure how to go about these tests, JUnit" New topic

Not sure how to go about these tests, JUnit

Tom Mordon
Ranch Hand

Joined: Apr 26, 2012
Posts: 30
I'm a beginner with JUnit and am somewhat stumped on how to go about testing these large methods. Looking for input as to how I should go about attacking these methods. Pasted first are the three methods I'm trying to crack and below that are the JUnit test methods that came up. So far I've only had fairly simple methods that I have had to test so these have thrown me off a bit. Any input is appreciated. Thanks much!

Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30057

You can test the code by reading in the hard coded file, but that's hard. It would be better to pass in the filename so you could use a test file. Or pass in a Reader, so you can pass in a StringReader and not have to deal with files at all.

IN terms of going one step further, you read test method needs to instantiate d. It also needs an assert.

[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:
subject: Not sure how to go about these tests, JUnit
Similar Threads
Testing void method in Junit
Test Results 4 failed tests JUnit
What causes this null pointer exception in SortedMap/TreeMap?
JUnit testing with int[] result
Array Index Out Of Bounds Exception