Hello,
I'm struggeling to find reliable information about how to write automated test when using Neo4J.
I found of course the documentation telling to use TestGraphDatabaseFactory().newImpermanentDatabase()
. But that's only valid when we use an embedded database right?
But what about when our production code access the database using the Java driver?
Is there an adapter from GraphDatabaseService to Driver (or vice-versa)?
You can check this blog post showing how to use test containers for integration testing :
Thanks for the quick answer.
Is there any alternative to using docker? (Docker doesn't run in many of our machines)
Well this is not about running docker or not, it is just convenient as it represent a real detached Neo4j instance from your JVM.
You can also check the Neo4jRule in this example :
User-defined procedures - Java Reference
Well this is not about running docker or not
hem... Yes it is. It relies on testcontainers and for that it does need an installation of docker on the machine running the tests.
You can also check the Neo4jRule in this example
That sound closer to what I want. Except it require Juni4 and the example is dedicated to testing stored procedure.
How can I do for any arbitrary testing framework?
Could I find somewere an example of how to test arbitrary code using a driver? (not only stored procedure)
Docker is generally available in any CI tools available nowadays.
The @Rule example is not dedicated to testing procedures, it is an embedded database exposing the bolt port, so you should be good with that.
Ok, exploring how the rule is implemented, I found that I can use TestServerBuilders.newInProcessBuilder().newServer()
from the neo4j-harness
artifact.
However, I cannot close the server. Calling ServerControls#close()
fails with the following exception:
Component 'org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter@716a6343' failed to stop. Please see the attached cause exception "null".
org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter@716a6343' failed to stop. Please see the attached cause exception "null".
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.stop(LifeSupport.java:488)
at org.neo4j.kernel.lifecycle.LifeSupport.stopInstances(LifeSupport.java:161)
at org.neo4j.kernel.lifecycle.LifeSupport.stop(LifeSupport.java:143)
at org.neo4j.server.AbstractNeoServer.stop(AbstractNeoServer.java:392)
at org.neo4j.harness.internal.InProcessServerControls.close(InProcessServerControls.java:85)
... 15 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at org.neo4j.server.web.Jetty9WebServer.stop(Jetty9WebServer.java:176)
at org.neo4j.server.AbstractNeoServer.stopWebServer(AbstractNeoServer.java:399)
at org.neo4j.server.AbstractNeoServer.access$800(AbstractNeoServer.java:102)
at org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter.stop(AbstractNeoServer.java:535)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.stop(LifeSupport.java:480)
... 18 more
Caused by: java.lang.NullPointerException
at org.eclipse.jetty.util.IO.delete(IO.java:345)
at org.eclipse.jetty.webapp.WebInfConfiguration.deconfigure(WebInfConfiguration.java:363)
at org.eclipse.jetty.webapp.WebAppContext.stopContext(WebAppContext.java:1471)
at org.eclipse.jetty.server.handler.ContextHandler.doStop(ContextHandler.java:990)
at org.eclipse.jetty.servlet.ServletContextHandler.doStop(ServletContextHandler.java:297)
at org.eclipse.jetty.webapp.WebAppContext.doStop(WebAppContext.java:569)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:149)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:170)
at org.eclipse.jetty.server.handler.AbstractHandler.doStop(AbstractHandler.java:124)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:149)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:170)
at org.eclipse.jetty.server.handler.AbstractHandler.doStop(AbstractHandler.java:124)
at org.eclipse.jetty.server.Server.doStop(Server.java:490)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.neo4j.server.web.Jetty9WebServer.stop(Jetty9WebServer.java:172)
... 22 more
Any clue?