lundi 4 mai 2015

How to mock controllers / rest endpoints for unit testing in Play Framework 2.x [Java]

We are developing a project with Java on Play Framework 2.x and have some rest endpoints. Also we have some test cases for them like as follows:

    @Test
    public void testLogout() throws Exception {
        FakeRequest request = new FakeRequest("GET", "/product/api/v1/logout");

        Result result = route(request);

        assertThat(status(result)).isEqualTo(OK);
        assertThat(contentType(result)).isEqualTo("application/json");
        assertThat(contentAsString(result)).contains("result");
    }

On the other hand, we have some methods [like register()] which can not test in production database.

What is the correct way to test the methods which affect the prod database? I think mocking but I am not sure that and I don't know how to do. If mocking is a good choice, is there any working example?

Please give me some advice about this issue.

Aucun commentaire:

Enregistrer un commentaire