java - Unit test for Spring controller have RequestPart String param -
i must write unit test using junit spring web project. controller have parameter like
@requestmapping(value = "/tasks/{id}/", method = requestmethod.put) public responseentity<string> unlock( @pathvariable string id, @requestpart string param)
i dont know param receive. use @requestpart multipartfile.
- in test, inject class.
- add mockmvc (is part of spring test let call ws).
- prepare mock, ie:
when(myclassinjected.mymethod()).thenreturn(the_result);
- perform call mockmvc. (you can follow tutorial @ end of post)
- verify call, ie:
verify(myclassinjected, times(1)).mymethod();
check this tutorial more information.
Comments
Post a Comment