Integration Testing Against Remote Neo4j
By: Adam George
Writing integration tests for your code that runs against Neo4j is simple enough when using the native API, but there's not a great deal of help out there if you're working in client-server mode. Making assertions about the shape of the graph can also be difficult, particularly if use cases involve more than a few nodes and relationships.
In all but the most simple of scenarios, it can be hard to see why the graph in the test database isn't as expected, as the feedback is often as black-and-white as pass/fail so you can be looking for a proverbial needle in a haystack when trying to pinpoint the problem.
Fortunately, GraphAware have developed a neat little utility called GraphUnit that does all the hard work for you. To take advantage of it, you'll need to make sure that the following Java dependencies are on your classpath. If you're unlucky enough to be using Maven, you can just copy the following XML block into your POM file.
You can learn all about how to use GraphUnit in embedded mode by reading this blog post but what about client-server mode? If you've got a use case where you're testing against the transactional Cypher endpoint or one of the REST APIs then you'll need to consider this. If you have unmanaged extensions then it can also be useful for verifying that these work correctly in their natural environment.
Since JUnit 4.9, Rules have been available for instrumenting your test cases. These offer a much more flexible approach than custom runners and abstract base classes and bootstrapping Neo4j is a great use for them.
... to read more articles, visit http://sqa.fyicenter.com/art/