////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

It is relatively trivial to write unit tests that use GORM for Neo4j. If you wish to use an embedded version of Neo4j simply add the `neo4j-harness` dependency to your `build.gradle` file:

[source,groovy,subs="attributes"]
.build.gradle
----
testRuntime "org.neo4j.test:neo4j-harness:{neo4jVersion}"
----

Then create a https://spockframework.org[Spock] specification and declare a `@Shared` field using the `Neo4jDatastore` constructor with the domain classes you wish to test:

[source,groovy]
----
include::{testsdir}/grails/gorm/tests/assignedid/OneToManyCreateSpec.groovy[tags=setup,indent=0]
----

NOTE: The `@AutoCleanup` annotation will ensure the datastore is shutdown correctly after the test completes

If the test is in the same package as your domain classes then you can also setup package scanning instead of hard coding each domain class name:

[source,groovy]
----
@Shared @AutoCleanup Neo4jDatastore datastore
        = new Neo4jDatastore(getClass().getPackage())
----

Then annotate each test method with the `grails.gorm.transactions.Rollback` annotation:

[source,groovy]
----
@Rollback
void "test something"() {

}
----