Database Reference
In-Depth Information
Testing frameworks for Neo4j
In the previous section, we talked about Neo4j and the process of writing JUnit using the
framework provided by http://junit.org .
We also discussed the shortcomings of JUnit because of the boilerplate code that needs to
be written, even for a simple JUnit. It not only takes time but is also difficult to maintain.
To overcome all these shortcomings, frameworks such as GraphUnit— ht-
tp://graphaware.com/ —and AssertJ— http://joel-costigliola.github.io/assertj/assertj-
neo4j.html —were evolved which provide various assertions to reduce unnecessary code
(boilerplate code) and help developers to focus on writing effective and efficient unit tests.
Let's enhance our test suite, that is, neo4j.tests.Neo4jTest.java and see how we
can leverage assertions provided by GraphUnit and AssertJ.
Perform the following steps to develop unit tests using GraphUnit:
1. Open your MyNeo4jSamples/pom.xml file and add the following dependen-
cies within the <dependencies> section:
<dependency>
<groupId>com.graphaware.neo4j</groupId>
<artifactId>tests</artifactId>
<version>2.1.5.25</version>
<scope>test</scope>
</dependency>
2. Add another function by the name of compareNeo4jDatabase() and add the
following code:
@org.junit.Test
public void compareNeo4jDatabase() {
//Open a Transaction
try(Transaction transaction=graphDb.beginTx()){
String testLabel="TestNode";
//Create a Node with Label in the neo4j Database
graphDb.createNode(DynamicLabel.label(testLabel));
transaction.success();
}
Search WWH ::




Custom Search