I am unit testing domain logic and domain objects backed by a neo4j database. Most of these tests need to mock the neo4j GraphDatabaseService, various Nodes, and various Relationships. Some of the mocked methods return these mocked objects. For example, a getReferenceNode() call returns a mocked Node or a getSingleRelationship() call returns a mocked Relationship whose getEndNode() in turn returns a mocked Node.
I’m concerned by the number of mocks returning mocks returning mocks. Usually, this isn’t recommended. It certainly complicates the test setup and leads to quite brittle tests, because so many layers of neo4j functionality need to be mocked.
Is there a way to avoid this when unit testing neo4j-backed domain logic?
You could try using a temporary database–one that gets created/flushed every time. In case you need to sample data then you could: