jeudi 19 juillet 2018

Spring Boot: what is the best strategy to unit test repository methods?

We have a lot of methods with joins and fetches that look like :

@Query(
        "select new com.vulog.user.entity.DTO.UserBillingDTO(" +
                    "u.id as id, " +
                    "u.firstName as firstName, " +
                    "u.lastName as lastName, " +
                    "e.tokenId as billingTokenID," +
                    "u.fleetId as fleetId," +
                    "e.id as entityId, " +
                    "u.userName as userName, " +
                    "u.locale as locale) " +
                "from User as u "  +
                "join u.profiles as p "  +
                "join p.entity as e "  +
                "where u.id = :userId")
UserBillingDTO findUserForBilling(@Param("userId") String userId);

I d like to cover such methods with tests and see if our hql queries are returning the expected results.

One obvious way would be to create entities in the test setup using code. But I am afraid the readability of this test will be very low.

Another idea that comes to my mind is to dump a database from our test platform, use it to setup tests and then only run queries to check the results.

Can you think of anything else? How could I write a maintainable test suite that is easy-to-follow for the team?

Thanks.

Aucun commentaire:

Enregistrer un commentaire