Meaningless Drivel is fun!*
The moose likes Testing and the fly likes how to test functions who use java io classes like LineNumberReader and FileReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "how to test functions who use java io classes like LineNumberReader and FileReader" Watch "how to test functions who use java io classes like LineNumberReader and FileReader" New topic
Author

how to test functions who use java io classes like LineNumberReader and FileReader

Jigar Gosar
Ranch Hand

Joined: Jul 09, 2002
Posts: 95
I have following method in my class, I was wondering how could i write a unit test for a method that does file io, and uses java io classes such as FileReader, and LineNumberReader. I did some googling on "junit java io" "junit testing LineNumberReader" but didnot find anything useful.

Any help is appreciated.


[ March 09, 2006: Message edited by: Jigar Gosar ]

Regards,<br />Jigar Gosar (SCJP 1.4)<br />visit: <a href="http://jigar.org/blog" target="_blank" rel="nofollow">http://jigar.org/blog</a>
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Break the method into two as shown, then test the non-public one using data in a StringReader:



[Jess in Action][AskingGoodQuestions]
 
Consider Paul's rocket mass heater.
 
subject: how to test functions who use java io classes like LineNumberReader and FileReader
 
Similar Threads
this code is giving file not found exception
reading a file by lines
reading a file by lines
programatic diff tool
declaring array of vectors