Newer
Older
labs / tiddlers / content / labs / lab02 / _Labs_02_Initial Set-Up.md

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.

  1. Add the jacoco plugin to the plugins section. The complete section should look like:

    plugins {
      id "application";
      id "jacoco";
    }

    We will explain what JaCoCo is in a later section.

  2. Add the testing library dependencies to the project. The following section should be added to the bottom of the build script at the root level (not inside any other curly braces):

    dependencies {
      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)
    • Hamcrest
    • JaCoCo

    We will explain what each of these frameworks is doing as we go.

  3. Add the test section to the bottom of the build script at the root level to tell Gradle which testing framework to use when running automated tests:

    test {
      useJUnitPlatform();
    }
  4. Save the file.

  5. 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.