Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give the multipart file input in junit

Tags:

java

junit

spring

I am using JUnit for testing of Daoimpl. In one of the cases, I need to give an input which is a multipart file. I searched the internet and found that mockmultipartfile is used, but didn't find any example. Please provide me one for better understanding.

I am using spring and JUnit 4.11

like image 649
vishal Avatar asked Mar 07 '14 08:03

vishal


1 Answers

I have done the multipart file as a input for junit by using [MockMultipartFile].

FileInputStream inputFile = new FileInputStream( "path of the file");  
MockMultipartFile file = new MockMultipartFile("file", "NameOfTheFile", "multipart/form-data", inputFile); 

now use the file input as multipart file.

like image 189
vishal Avatar answered Sep 18 '22 23:09

vishal