Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage Presentations Spring 3.1 and MVC Testing Support

Spring 3.1 and MVC Testing Support



Sam Brannen and Rossen Stoyanchev introduce the TestContext Framework, how to use @Configuration and environment profiles for testing with Spring 3.1, and the testing support available in Spring MVC.


Sam Brannen is a Senior Software Consultant with over 13 years' experience, co-founder of Swiftmind, former Spring Core and dm Server developer and lead author of Spring in a Nutshell. Rossen Stoyanchev is an engineer for SpringSource, a committer on the Spring MVC and the Spring Web Flow projects, and author of a Spring Web course.

About the conference

SpringOne 2GX is a one-of-a-kind conference for application developers, solution architects, web operations and IT teams who develop business applications, create multi-device aware web applications, design cloud architectures, and manage high performance infrastructure. The sessions are specifically tailored for developers using the hugely popular open source Spring technologies, Groovy & Grails, and Tomcat. Whether you're building and running mission-critical business applications or designing the next killer cloud application, SpringOne 2GX will keep you up to date with the latest enterprise technology.

Recorded at:

Mar 02, 2012

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Test a uploading file Controller

    by Alberto García Rubio,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Congratulations for the presentation. Very interesting and useful.

    I am trying to test a controller with the spring-mvc-test but I cannot get it work correctly. The functionality of my controller is to upload a file to a server, so it has as method parameter a class embendding a CommonsMultiparFile. This is the signature of the upload method

    public @ResponseBody
    String createOperationDocument(HttpServletRequest request,@RequestParam String name,@RequestParam String description,FileUploadBean uploadItem){}

    The Class FileUploadBean is the one embedding the commons CommonsMultipartFile:

    public class FileUploadBean {

    private CommonsMultipartFile file;

    public CommonsMultipartFile getFile() {
    return file;

    public void setFile(CommonsMultipartFile file) {
    this.file = file;

    I am testing this method following the tips in this presentation:

    MockMvc mockMvc = xmlConfigSetup("classpath:*.xml").build();
    MultipartRequestBuilder mrb = fileUpload("/documentManager/createOperationDocument");
    mrb.param("description", "descripcion test.pdf");
    mrb.param("name", "test.pdf");
    byte[] data = {1,2,3,4,5};
    MockMultipartFile file = new MockMultipartFile("test.pdf", data);

    ResultActions resultActions = mockMvc.perform(mrb);

    When Executing the test, the controller method "createOperationDocument" is called but the parameter "FileUploadBean" is always null.

    Any idea whats happening? From the web application this method is called and it works fine, the "FileUploadBean" is no null and contains the file uploaded.


Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p