File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes need help: writing Junit test cases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "need help: writing Junit test cases" Watch "need help: writing Junit test cases" New topic

need help: writing Junit test cases

J Srinivasarao

Joined: Oct 16, 2006
Posts: 2
How to intialize FormFile object in junit test cases?

I would like to write junit test case for method which has parameter FormFile.

I am getting this in general uploading the file in jsp <html:file> struts tag.

Thanks in advance
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

Welcome to JavaRanch!

FormFile is an interface in Struts. So you would use a mock object to simulate it. You can write your own class to implement the interface. Or more likely, you will want to use a framework like jMock or easyMock to do this for you.

[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
J Srinivasarao

Joined: Oct 16, 2006
Posts: 2

Thanks for quick response ,

Do you have any examples like this.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Although Jeanne is correct that you can use mocks in such a case, in my opinion they are rather deep in the bag of tricks, especially if you are rather new to JUnit.

So what I would look at beforehand is whether you really need to pass a FormFile object to that method. Can you perhaps abstract away from that Struts class and pass in an object that would make the test easier to write? What is the method doing you want to test?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: need help: writing Junit test cases
It's not a secret anymore!