GraphAware Blog - Testing

Automated testing is the cornerstone of any successful software project.Applications using the Neo4j database are no exception. This blog postshows how to use the Neo4j Dockerimage and the Testcontainerslibrary for integration testing inJava using JUnit.This blog post shows examples in Java. Testcontainers library has beenported to many other languages so the same approach and principles canbe applied. Check out theTestcontainersgithub page.MotivationNeo4j already provides a testing harness to start a temporary databasewithin tests, either manually or through a JUnit rule. To use thisharness one must include theneo4j-harnessmaven artifact, together with whole Neo4j database as a testdependencyto the project. This inevitably pollutes...

Writing integration tests for your code that runs against Neo4j is simple enough when using the native API, but there’snot a great deal of help out there if you’re working in client-server mode. Making assertions about the shape of thegraph 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 haystackwhen trying...

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.SetupGrab 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 itAll you have to do is POST your cypher to http://your-server-address:7474/graphaware/resttest/assertSameGraph orhttp://your-server-address:7474/graphaware/resttest/assertSubgraph to verify the state of your graph.Emptying the database...

Testing the state of an Embedded Neo4j database is now much easier if you use GraphUnit, a component of the GraphAware Neo4j Framework.I tried replacing an existing Flavorwocky unit test with GraphUnit to check out the benefits.Let’s walk through a before-after case study.The testThe unit test in question is the one to test that a Pairing is saved correctly. A pairing must have exactly two ingredients. Each Ingredient node has a name; a Pairing has an affinity and an array of allAffinities (all affinities ever assigned to the pairing).BeforePseudocode to test that my code saved a pairing correctly in Neo4j:...

Recently, we announced the GraphAware Framework. Today, I would like to introduce its first feature called GraphUnit. GraphUnit is a component that helps Java developers unit test their code that talks to Neo4j and mutates data.Unit Testing Neo4j CodeWhen writing Java code that modifies data stored in Neo4j, developers can use the ImpermanentGraphDatabase in conjunction with any of APIs provided by Neo4jto test that code. This includes the native Java API, the traversal framework, and Cypher.(I’ve excluded the REST API because using that to unit test Java code wouldn’t make much sense.)Let’s say we’re testing code that creates two nodes...