Neo4j Server Unit Testing with RestTest

Luanne Misquitta

by Luanne Misquitta

A couple of days ago, I wrote about unit testing with GraphUnit. GraphUnit tested the state of an embedded Neo4j database. What if you run Neo4j in standalone server mode? Fortunately, you can still test it and match subgraphs using the GraphAware Neo4j RestTest library.


Grab the GraphAware Neo4j Framework and GraphAware Neo4j RestTest jars from the Downloads page. Drop them into the plugins directory of your Neo4j installation and restart the server to be able to use the API’s.

How to use it

All you have to do is POST your cypher to http://your-server-address:7474/graphaware/resttest/assertSameGraph or http://your-server-address:7474/graphaware/resttest/assertSubgraph to verify the state of your graph.

Emptying the database before the next test is achieved via POSTing to http://your-server-address:7474/graphaware/resttest/clear


Continuing with the sample project from the previous post, we’ve moved away from embedded Neo4j and instead talk to a Neo4j server. ConnectionFactory now returns a handle to a JDBC Connection.

BaseTest uses the RestTest endpoints to

    1. Clear the database at the end of a test class
  • 2.Assert that the entire graph is matched
    1. Assert that a subgraph is matched

The unit test itself remains mostly unchanged.

Not just Java

Conveniently exposed as REST endpoints, RestTest lends itself nicely to testing against your Neo4j server in any language that can make an HTTP request.


Share this blog post:

comments powered by Disqus