• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

need help: writing Junit test cases  RSS feed

 
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
 
author & internet detective
Posts: 39283
727
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.
 
author
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?
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!