dimanche 5 avril 2015

Unit Test API REST Spring

I would like to do some unit tests for my API REST (Spring Boot App)


I have been reading this: http://ift.tt/19VZzPU


I have made my first test:



@RunWith(SpringJUnit4ClassRunner.class)


@WebAppConfiguration public class LogInTest {



private MockMvc mockMvc;

//Add WebApplicationContext field here.

//The setUp() method is omitted.

@Test
public void findAll_TodosFound_ShouldReturnFoundTodoEntries() throws Exception {

mockMvc.perform(get("/logIn?name=dani&encrypted=81dc9bdb52d04dc20036dbd8313ed055"))
.andExpect(status().isOk())
.andExpect(content().contentType(TestUtil.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(2)))
.andExpect(jsonPath("$[0].status", is(1)))
.andExpect(jsonPath("$[0].error", is("")))
.andExpect(jsonPath("$[0].data", is("OK")));
}


}


When I run the test as JUnit test I get the following error: java.lang.IllegalStateException: Failed to load ApplicationContext


I don't know how to add - WebApplicationContext field here - setUp() method


Can someone give me an example of WebApplicationContext and setUp() method?


Thanks


Aucun commentaire:

Enregistrer un commentaire