Neo4j Server Unit Testing with RestTest
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.
Setup
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
Example
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
-
- Clear the database at the end of a test class
- 2.Assert that the entire graph is matched
-
- 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.
Read more at https://github.com/graphaware/neo4j-resttest