Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help: writing Junit test cases

 
J Srinivasarao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
J Srinivasarao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for quick response ,

Do you have any examples like this.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic