JUnit Dependencie
In order to test our entities, we must include JUnit in our project's dependencies.
Testing our entities will ensure that we have properly configured our JPA environment (in the persistence.xml) and annotated our entity classes correctly.
Drill¶
- First things first, we need to include testing dependencies in our
build.gradlefile.ext { hibernateVersion = "5.4.32.Final" mySqlConnectorVersion = "8.0.27" junit5Version = "5.8.2" } // define project specific dependencies dependencies { implementation "mysql:mysql-connector-java:$mySqlConnectorVersion" implementation "log4j:log4j:1.2.17" implementation "org.hibernate:hibernate-core:$hibernateVersion" implementation "org.hibernate:hibernate-c3p0:$hibernateVersion" testImplementation("org.junit.jupiter:junit-jupiter:$junit5Version") }
Since this dependency is used only in testing, we add it to our dependencies with the
testImplementationconfiguration.Now we tell Gradle to use JUnit when its
testtask is run - add this after thedependenciesblock:test { useJUnitPlatform() }
- Make sure you save your
build.gradlebefore you run a Gradle refresh. Our project is now set up for creating JUnit tests.