I want to test the storage layer of my application. The storage layer access the database and map the model with the database schema using JPA.
As example take a storage layer for an application that visualizes books. The model has two entities: books and authors. A book can have one or more authors. The storage layer exposes methods for listing books, authors or more complex operation like all the books for a certain author.
I'm trying to understand how and what I've to test in my storage layer.
Database
- Should I test the connection?
Model
- Should I test the model?
- Should I test the JPA annotations in the model? For example joins between books and authors.
- Should I test if the model matches the schema? For example fields and tables name.
Storage logic (DAO)
- Should I test the DAO?
- Should I test the DAO isolating it from the EntityManagerFactory?
Storage layer
- Should I make an integration test that comprises DAO, JPA and DB?
- Should I test the storage layer logic using a test DB?
- If I use a test DB should it be filled with well know data, created specifically for the test, in order to make the correct assertions in my tests? For example test that if I ask for all the books for author X I get all the books.
- Should I test methods like listing that simply delegate the operation to JPA?
Other questions and suggestions are welcome.
Aucun commentaire:
Enregistrer un commentaire