jeudi 25 octobre 2018

The most proper way to test Service/DAO layer

Well, I'm using Spring and Hibernate. Now I am about to create tests for service/dao layer but I wonder what the best solution is.

I've seen some similar questions and here are the solutions people suggested:

(with the help of JUnit, certainly)

  • Use in-memory database(H2, etc.)
  • Use Mockito and mock a DAO/Service layer
  • Use Spring to help to test, viz.:

    Use annotations
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes = {AppConfig.class})

    and then just autowire service/dao and test it.

Thus, the first question is: what's the best solution to test Service layer(considering that I'm using Spring MVC and Hibernate with MySQL)
And the second: should I test DAO layer If I test Service layer(which already consists of DAO's methods)?

Aucun commentaire:

Enregistrer un commentaire