my dog learned polymorphism*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "need help: writing Junit test cases" Watch "need help: writing Junit test cases" New topic
Author

need help: writing Junit test cases

J Srinivasarao
Greenhorn

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
Srinivas
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Srinivas,
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
Greenhorn

Joined: Oct 16, 2006
Posts: 2
Hi

Thanks for quick response ,

Do you have any examples like this.
Ilja Preuss
author
Sheriff

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: http://aspose.com/file-tools
 
subject: need help: writing Junit test cases
 
Similar Threads
JUnit Test Cases with Hibernate
Run as Junit Test case
Junit for struts FormFile
Writing Test Case
how to write and run junit test cases in eclipse?