1

Am starting to write unit tests along the lines of https://github.com/neo4jrb/neo4j/wiki/How-To-Test

One of the approaches there is really slow (10 seconds per test) and the other doesn't delete labels (and probably other things)

Can anyone suggest a more elaborate approach? I noticed that in the core neo4j material, the java documentation describes methods that create and tear down temporary databases, but I don't see a way to access those from the (very nice) ruby and rails neo4j gems. Perhaps via the low-level REST api? It's hard to figure out what api calls are available.

Alex Edelstein
  • 518
  • 5
  • 19

1 Answers1

1

So you could probably surround your tests in transactions which is a typical approach for testing with ActiveRecord in Ruby. That might be more performant, but it should also help keep the database clean.

But you're right, the impermanent database is the tool that's provided in Neo4j for temporary databases for testing. I think that's only available if you're running JRuby, though. I did run across this, though:

https://groups.google.com/forum/#!topic/neo4j/7xeEPWEiqD0

Which links to a project which lets you start up a Neo4j server in "in memory" mode (using the impermanent database):

https://github.com/jexp/neo4j-in-memory-server

That's showing examples for Neo4j 2.0.0, so I don't know if it would work for later versions, but it might be worth a shot for your testing database.

EDIT: Another thing that I just thought of is to use the vcr gem:

https://github.com/vcr/vcr

It basically records all of the requests made to your server and then plays them back. This works great for API endpoints where result are idempotent, but if you use it for a database like Neo4j you should make sure that your tests are clearing the database before every test run so that it always starts fresh

Brian Underwood
  • 10,746
  • 1
  • 22
  • 34