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.

  1. in test, inject class.
    1. add mockmvc (is part of spring test let call ws).
    2. prepare mock, ie: when(myclassinjected.mymethod()).thenreturn(the_result);
    3. perform call mockmvc. (you can follow tutorial @ end of post)
    4. verify call, ie: verify(myclassinjected, times(1)).mymethod();

check this tutorial more information.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -