The moose likes Testing and the fly likes about MultipartFile with Junit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "about MultipartFile with Junit" Watch "about MultipartFile with Junit" New topic

about MultipartFile with Junit

karas huang

Joined: Dec 22, 2013
Posts: 2
Sorry about my pool english, i'm come from taiwan,
I can use google translate to express my problem, I hope seniors understanding.
JAVA has just entered less than six months,
I recently encountered this problem ... no clue
Architecture is Spring + hibernate

The main problem is actually very short,
I used several methods are unable to successfully simulate a file allows itself controller to eat,
Cause is a program that has been unable to pass the test, relative to the coverage itself has been unable to meet the requirements.


Use of the following two results,
PropertyUtils.getProperty went here are signs (green background),
But continued to go down to determine the file size, not passed.

Junit part1.

Junit part2.

Thanks for watch, i really need your help with this....
E Armitage

Joined: Mar 17, 2012
Posts: 989
It is easy to read the code and test it if you collect conditions into meaningful methods.
So replace

Now you have two conditions to test instead of four conditions. You can then write and test the notEmpty method separately which will be easy to do.

Also, don't use in unit tests. Load the file from the classpath using
karas huang

Joined: Dec 22, 2013
Posts: 2
Thanks you so much,
i used your way,
then i fix the fileinput problem,
at the last,
i have other problem with MockMultipartHttpServletRequest,
but i still fix that.

Thanks you.
I agree. Here's the link:
subject: about MultipartFile with Junit
It's not a secret anymore!