File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Any JUnit Test Could be Written for Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Any JUnit Test Could be Written for" Watch "Any JUnit Test Could be Written for" New topic

Any JUnit Test Could be Written for

Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
Hi, thank you first for reading my post.

I have a very simple "marshaller" class (see below). I wonder if any JUnit test could be written for it. Would you please suggest if there is any?
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

i think no..Let see what other can say...

SCJP6.0,My blog Ranchers from Delhi
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Possibly not based on the way the code is written, however it would be easy enough to rewrite it to support test cases.

The question I would have, though, is what are you trying to test? The code you have provided is basically marshaling a bean. You should not really need to unit test your beans or third-party libraries. Take those two out of the equation, and you have almost nothing to test.

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33133

Why can't a JUnit test be written? You call the method and then read the file on the file system to see if the results are what you expected.

If you are talking about a pure unit test without the file system, you'd need to refactor.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Any JUnit Test Could be Written for
It's not a secret anymore!