We need to add some bits and pieces to the
build.gradle file to add support for unit testing to the project. You can find the file in NetBeans under the <> folder in the projects pane.
jacoco plugin to the
plugins section. The complete section should look like:
We will explain what JaCoCo is in a later section.
Add the testing library dependencies to the project. The following section should be added to the bottom of the build script:
def junitVer = "5.8.2";
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVer;
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVer;
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2';
There are three frameworks being used here:
- JUnit 5 (also known as Jupiter)
We will explain what each of these frameworks is doing as we go.
test section to the bottom of the build script to tell Gradle which testing framework to use when running automated tests:
Save the file.
You may get some warnings in your project at this point. This is because your project is using libraries that Gradle has not yet downloaded. Build the project using < Build Project">> --- this will force Gradle to download everything it needs and should fix any problems.