Speed Up Spring MockMvc Integration Test with Embedded Cassandra

Viewed 1672

We are using MockMvc Framework to test Spring Controllers with JUnit. Controller returns a DefferedResult.

The mockmvc.perform looks like bellow

mockMvc.perform(post("/customer")
                .accept(APPLICATION_JSON)
                .header(AUTH_TOKEN_KEY, "xyz")
                .header(FROM_KEY, "email@gmail.com")
                .content(json)
                .contentType(APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(request().asyncStarted());

And it takes a lot of time. We are Using embedded cassandra and because of that it takes a lot of time.

I tried this as well, but it's same.

MvcResult mvcResult = mockMvc.perform(post("/customer")
            .accept(APPLICATION_JSON)
            .header(AUTH_TOKEN_KEY, "xyz")
            .header(FROM_KEY, "email@gmail.com")
            .content(json)
            .contentType(APPLICATION_JSON))
            .andReturn();

mockMvc.perform(asyncDispatch(mvcResult))
            .andExpect(status().isOk())
            .andExpect(request().asyncStarted());

I've hundreds of tests, because of which the build process is really slow.

Is there a way, using JUnit I can say perform the request and wait for response in another thread to assert the results, Or anyother good way of speeding it up.

Thanks

3 Answers
Related