A ApprovalTests.Net reporter and approver to be used to unit test Neo4j with the Neo4jClient .net client
This project comes to solve the problem of visual approving Neo4j graphs during unit testing. It makes it very easy to visualize the current state of the graph and see diffrences between the approved graph and the changes made by new code. It can also be uses to visualize query results if the query returns nodes and edges (see the tests project included within this reposetory).
Install-Package Neo4jClientApprovalTests
Please note: The nuget package is installing an old version of ApprovalUtilities. I will try to fix it soon. As a workaround, after installing the Neo4jClientApprovalTests package, update the ApprovalUtilities package by running Update-Package ApprovalUtilities
.
Just add [UseReporter(typeof(Neo4jReporter)]
attribute on the test class or test method. See the AprrovalTests documentation
In your test method use Neo4jApprover.VerifyGraph(GraphClient)
to test the graph.
Use Neo4jApprover.VerifyQuery(IEnumerable<GraphNode> nodes, IEnumerable<GraphEdge> edges, bool leaveNodeIdsUnchanged = false)
to validate a query (see test project for an example).
The reporter will be opened within your default browser. AS vis.js uses HTMl5 canvas - so you'll need a modern browser. I tested it with Chrome v45.
Note 1: You should delete the graph before each test and use a temporery Neo4j database for testing. You can use Neo4j Docker image to run the temp DB
Note 2: Whenever data is inserted to Neo4j it creates a new internal ID. Beacuse in unit tests we are always recreating the data the IDs will be diffrent each time. To over come this, the IDs are replaced with new ids starting from 1. Potantialy this beavior can create s false positive.
[TestClass, UseReporter(typeof(Neo4jReporter))]
public class Neo4jReporterTests
{
[TestMethod]
public void TestGraph()
{
GraphClient graph = new GraphClient(new Uri("..."));
graph.Connect();
graph.Cypher
.Create("(a:WORD {name:'Hello'})-[:NEXT {times: 5}]->(b:WORD {name:'world'}), (b)-[:PREV]->(a)")
.ExecuteWithoutResults();
Neo4jApprover.VerifyGraph(graph);
}
}
At first, there is nothing to compare to, so just approve it if it is the right graph
Compare to approved graph