Software QA FYI - SQAFYI

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.

GraphUnit
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.

<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>2.2.4</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>tests</artifactId>
<version>2.2.4.34</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>


Server Mode
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.

JUnit Rules
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.

Full article...


Other Resource

... to read more articles, visit http://sqa.fyicenter.com/art/

Integration Testing Against Remote Neo4j