Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Writing to file in JUnit test case? Not working?

807591Mar 13 2008 — edited Mar 13 2008
I have a singleton class called InstantLogger that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.

When I use this class outside of the JUnit test suite it works fine.

As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.

Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?

Thanks,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 10 2008
Added on Mar 13 2008
5 comments
1,135 views