cancel
Showing results for 
Search instead for 
Did you mean: 

How do people write test suites without a checkpoint/snapshot function?

bradenmacdonald
Node Link

Hi everyone,

I'm curious how people approach writing test suites for applications that use Neo4j, in particular how to keep the tests isolated from each other, while still keeping test performance fast?

For background, I came to Neo4j from web development with Django, and its SQL ORM. Their test runner loads fixtures before running tests and then uses nested SQL transactions and/or SAVEPOINTs so that every test case is completely isolated from others and can freely read and write from the database without affecting data that may be used by other tests.

But as far as I can tell, Neo4j does not have any support for savepoints, nested transations, or anything that could quickly reset the database to a known state after each test runs, while still allowing the individual tests to open their own transactions and modify the database.

What I've been doing to date is using my Vertex Framework's snapshotDataForTesting() method (apoc.export.cypher.all()) as a one-time setup to create the data fixtures and then I use resetDBToSnapshot() before each test to ensure that test sees a consistent state with the full sample dataset available, but isolated from writes of other tests. However, that just runs MATCH (n) DETACH DELETE n and then runs all the Cypher statements from the original fixture/export to re-create the database. The problem is that this is slow and makes the test suite take about seven minutes to run instead of probably a few seconds if there were native nested transactions or snapshots. (Keep in mind my sample data set is probably under 200 nodes, so we're not talking a lot of data - but deleting it all and re-creating it for every test really adds up.) I should note this approach also means most tests cannot run in parallel because writes do actually get committed and then reset, as opposed to kept in an outer transaction and discarded.

So: how do others approach this problem? And am I missing some useful functionality or tools here?

0 REPLIES 0