Reputation: 291
I'm learning how to write test cases and I've encounter a problem. I have a persistence unit with entityA that has not empty collection of Bs. The application workflow ensures that B is never empty and contains entities that have already been persisted. (Let's say a user has to choose email addresses from his address book)
Now I have a problem in testing persisting A. If I create A i must create a set of Bs (@NotNull). B doesn't exist in test db so I get an error "object references an unsaved transient instance".
I'm using dbunit so the question is: Is it all right to use entitymanager and select set of Bs, that have been loaded for test from xml files, then add them to A and persist A? It somehow doesn't sound like a unit test to me. What is the best practice to handle this situation
thanks
Upvotes: 0
Views: 48
Reputation: 691795
I don't see any other possibility. A has a dependency to B, so you need to have Bs in order to persist A. Since mocking is not possible in this case, you need to get your Bs from the database.
Upvotes: 1