This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
internet detective

Joined: May 26, 2003
Posts: 30138

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.

[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
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
Similar Threads
JUnit Test Cases with Hibernate
how to write and run junit test cases in eclipse?
Run as Junit Test case
Junit for struts FormFile
Writing Test Case